Updated unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
531937ebbc
commit
8b005ae012
|
@ -0,0 +1,145 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('InvoiceOut createManualInvoice()', () => {
|
||||
const userId = 1;
|
||||
const ticketId = 16;
|
||||
const clientId = 1106;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: userId},
|
||||
};
|
||||
const ctx = {req: activeCtx};
|
||||
|
||||
it('should throw an error trying to invoice again', async() => {
|
||||
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(true);
|
||||
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
let error;
|
||||
try {
|
||||
ctx.args = {
|
||||
ticketFk: ticketId,
|
||||
serial: 'T',
|
||||
taxArea: 'CEE'
|
||||
};
|
||||
await models.InvoiceOut.createManualInvoice(ctx, options);
|
||||
await models.InvoiceOut.createManualInvoice(ctx, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toContain('This ticket is already invoiced');
|
||||
});
|
||||
|
||||
it('should throw an error for a ticket with an amount of zero', async() => {
|
||||
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(true);
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
let error;
|
||||
try {
|
||||
const ticket = await models.Ticket.findById(ticketId, null, options);
|
||||
await ticket.updateAttributes({
|
||||
totalWithVat: 0
|
||||
}, options);
|
||||
|
||||
ctx.args = {
|
||||
ticketFk: ticketId,
|
||||
serial: 'T',
|
||||
taxArea: 'CEE'
|
||||
};
|
||||
await models.InvoiceOut.createManualInvoice(ctx, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toContain(`A ticket with an amount of zero can't be invoiced`);
|
||||
});
|
||||
|
||||
it('should throw an error when the clientFk property is set without the max shipped date', async() => {
|
||||
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(true);
|
||||
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
let error;
|
||||
try {
|
||||
ctx.args = {
|
||||
clientFk: clientId,
|
||||
serial: 'T',
|
||||
taxArea: 'CEE'
|
||||
};
|
||||
await models.InvoiceOut.createManualInvoice(ctx, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toContain(`Max shipped required`);
|
||||
});
|
||||
|
||||
it('should throw an error for a non-invoiceable client', async() => {
|
||||
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(true);
|
||||
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
let error;
|
||||
try {
|
||||
const client = await models.Client.findById(clientId, null, options);
|
||||
await client.updateAttributes({
|
||||
isTaxDataChecked: false
|
||||
}, options);
|
||||
|
||||
ctx.args = {
|
||||
ticketFk: ticketId,
|
||||
serial: 'T',
|
||||
taxArea: 'CEE'
|
||||
};
|
||||
await models.InvoiceOut.createManualInvoice(ctx, options);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
await tx.rollback();
|
||||
}
|
||||
|
||||
expect(error.message).toContain(`This client is not invoiceable`);
|
||||
});
|
||||
|
||||
it('should create a manual invoice', async() => {
|
||||
spyOn(models.InvoiceOut, 'createPdf').and.returnValue(true);
|
||||
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
ctx.args = {
|
||||
ticketFk: ticketId,
|
||||
serial: 'T',
|
||||
taxArea: 'CEE'
|
||||
};
|
||||
const result = await models.InvoiceOut.createManualInvoice(ctx, options);
|
||||
|
||||
expect(result.id).toEqual(jasmine.any(Number));
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -19,8 +19,18 @@ describe('InvoiceOut createPdf()', () => {
|
|||
};
|
||||
spyOn(got, 'stream').and.returnValue(response);
|
||||
|
||||
const result = await models.InvoiceOut.createPdf(ctx, invoiceId);
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
expect(result.hasPdf).toBe(true);
|
||||
try {
|
||||
const result = await models.InvoiceOut.createPdf(ctx, invoiceId, options);
|
||||
|
||||
expect(result.hasPdf).toBe(true);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ describe('InvoiceOut download()', () => {
|
|||
it('should return the downloaded fine name', async() => {
|
||||
const result = await models.InvoiceOut.download(1);
|
||||
|
||||
expect(result[1]).toEqual('text/plain');
|
||||
expect(result[2]).toEqual('filename="README.md"');
|
||||
expect(result[1]).toEqual('application/pdf');
|
||||
expect(result[2]).toEqual('filename="1.pdf"');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue