fix: refs #7211 tests
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-04-25 15:38:21 +02:00
parent 931c2c4f5e
commit 4e864fed52
1 changed files with 25 additions and 44 deletions

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