#7896 - 24.36 Dev To Test #2884

Merged
jsegarra merged 118 commits from dev into test 2024-08-27 10:32:53 +00:00
1 changed files with 40 additions and 21 deletions
Showing only changes of commit 65ba1d4664 - Show all commits

View File

@ -1,4 +1,5 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('InvoiceOut invoiceClient()', () => {
const userId = 1;
@ -22,6 +23,11 @@ describe('InvoiceOut invoiceClient()', () => {
};
const ctx = {req: activeCtx};
beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
it('should make a global invoicing by address and verify billing status', async() => {
spyOn(models.InvoiceOut, 'makePdf').and.returnValue(Promise.resolve(true));
@ -85,34 +91,47 @@ describe('InvoiceOut invoiceClient()', () => {
const options = {transaction: tx};
try {
console.log('Searching for client with ID:', clientId);
const client = await models.Client.findById(clientId, options);
console.log('Found client:', JSON.stringify(client, null, 2));
const client = await models.Client.findById(clientId, null, options);
await client.updateAttribute('hasToInvoiceByAddress', false, options);
if (!client)
throw new Error(`Client with id ${clientId} not found`);
ctx.args = {
clientId: clientId,
invoiceDate: Date.vnNew(),
maxShipped: Date.vnNew(),
companyFk: companyFk,
serialType: 'global'
};
console.log('Client before update:', JSON.stringify(client, null, 2));
console.log('Current hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
const invoiceOutId = await models.InvoiceOut.invoiceClient(ctx, options);
try {
console.log('Attempting to update hasToInvoiceByAddress');
await client.updateAttribute('hasToInvoiceByAddress', false, options);
console.log('Update successful');
} catch (updateError) {
console.error('Error updating hasToInvoiceByAddress:', updateError);
console.error('Error stack:', updateError.stack);
throw updateError;
}
const invoiceOut = await models.InvoiceOut.findById(invoiceOutId, null, options);
console.log('Client after update:', JSON.stringify(client, null, 2));
console.log('New hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
expect(invoiceOutId).toBeGreaterThan(0);
const allClientTickets = await models.Ticket.find({
where: {
clientFk: clientId,
or: [
{refFk: null},
{refFk: invoiceOut.ref}
]
}
}, options);
const billedTickets = await models.Ticket.find({
where: {refFk: invoiceOut.ref}
}, options);
const allTicketsBilled = allClientTickets.every(ticket => ticket.refFk === invoiceOut.ref);
expect(allTicketsBilled).toBe(true);
const billedAddresses = new Set(billedTickets.map(ticket => ticket.addressFk));
expect(billedAddresses.size).toBeGreaterThan(1);
console.log('Test completed successfully');
await tx.rollback();
} catch (e) {
console.error('Test failed:', e);
console.error('Error stack:', e.stack);
await tx.rollback();
throw e;
}