7336_devToTest #2414

Merged
alexm merged 220 commits from 7336_devToTest into test 2024-05-07 06:26:53 +00:00
1 changed files with 25 additions and 44 deletions
Showing only changes of commit 4e864fed52 - Show all commits

View File

@ -1,13 +1,10 @@
const models = require('vn-loopback/server/server').models;
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('InvoiceOut createManualInvoice()', () => {
const userId = 1;
const ticketId = 16;
const clientId = 1106;
const activeCtx = {
accessToken: {userId: userId},
};
const activeCtx = {accessToken: {userId: 1}};
const ctx = {req: activeCtx};
it('should throw an error trying to invoice again', async() => {
@ -18,13 +15,8 @@ describe('InvoiceOut createManualInvoice()', () => {
let error;
try {
ctx.args = {
ticketFk: ticketId,
serial: 'T',
taxArea: 'CEE'
};
await models.InvoiceOut.createManualInvoice(ctx, options);
await models.InvoiceOut.createManualInvoice(ctx, options);
await createInvoice(ctx, options, undefined, ticketId);
await createInvoice(ctx, options, undefined, ticketId);
await tx.rollback();
} catch (e) {
@ -47,17 +39,9 @@ describe('InvoiceOut createManualInvoice()', () => {
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 ticket.updateAttributes({totalWithVat: 0}, options);
await createInvoice(ctx, options, undefined, ticketId);
await tx.rollback();
} catch (e) {
error = e;
@ -75,13 +59,7 @@ describe('InvoiceOut createManualInvoice()', () => {
let error;
try {
ctx.args = {
clientFk: clientId,
serial: 'T',
taxArea: 'CEE'
};
await models.InvoiceOut.createManualInvoice(ctx, options);
await createInvoice(ctx, options, clientId);
await tx.rollback();
} catch (e) {
error = e;
@ -103,16 +81,9 @@ describe('InvoiceOut createManualInvoice()', () => {
let error;
try {
const client = await models.Client.findById(clientId, null, options);
await client.updateAttributes({
isTaxDataChecked: false
}, options);
await client.updateAttributes({isTaxDataChecked: false}, options);
ctx.args = {
ticketFk: ticketId,
serial: 'T',
taxArea: 'CEE'
};
await models.InvoiceOut.createManualInvoice(ctx, options);
await createInvoice(ctx, options, undefined, ticketId);
await tx.rollback();
} catch (e) {
@ -130,12 +101,7 @@ describe('InvoiceOut createManualInvoice()', () => {
const options = {transaction: tx};
try {
ctx.args = {
ticketFk: ticketId,
serial: 'T',
taxArea: 'CEE'
};
const result = await models.InvoiceOut.createManualInvoice(ctx, options);
const result = await createInvoice(ctx, options, undefined, ticketId);
expect(result.id).toEqual(jasmine.any(Number));
@ -146,3 +112,18 @@ describe('InvoiceOut createManualInvoice()', () => {
}
});
});
function createInvoice(
ctx,
options,
clientFk = undefined,
ticketFk = undefined,
maxShipped = undefined,
serial = 'T',
taxArea = 'CEE',
reference = undefined
) {
return models.InvoiceOut.createManualInvoice(
ctx, clientFk, ticketFk, maxShipped, serial, taxArea, reference, options
);
}