#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 models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('InvoiceOut invoiceClient()', () => { describe('InvoiceOut invoiceClient()', () => {
const userId = 1; const userId = 1;
@ -22,6 +23,11 @@ describe('InvoiceOut invoiceClient()', () => {
}; };
const ctx = {req: activeCtx}; 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() => { it('should make a global invoicing by address and verify billing status', async() => {
spyOn(models.InvoiceOut, 'makePdf').and.returnValue(Promise.resolve(true)); spyOn(models.InvoiceOut, 'makePdf').and.returnValue(Promise.resolve(true));
@ -85,34 +91,47 @@ describe('InvoiceOut invoiceClient()', () => {
const options = {transaction: tx}; const options = {transaction: tx};
try { try {
console.log('Searching for client with ID:', clientId); const client = await models.Client.findById(clientId, null, options);
const client = await models.Client.findById(clientId, options); await client.updateAttribute('hasToInvoiceByAddress', false, options);
console.log('Found client:', JSON.stringify(client, null, 2));
if (!client) ctx.args = {
throw new Error(`Client with id ${clientId} not found`); clientId: clientId,
invoiceDate: Date.vnNew(),
maxShipped: Date.vnNew(),
companyFk: companyFk,
serialType: 'global'
};
console.log('Client before update:', JSON.stringify(client, null, 2)); const invoiceOutId = await models.InvoiceOut.invoiceClient(ctx, options);
console.log('Current hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
try { const invoiceOut = await models.InvoiceOut.findById(invoiceOutId, null, options);
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;
}
console.log('Client after update:', JSON.stringify(client, null, 2)); expect(invoiceOutId).toBeGreaterThan(0);
console.log('New hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
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(); await tx.rollback();
} catch (e) { } catch (e) {
console.error('Test failed:', e);
console.error('Error stack:', e.stack);
await tx.rollback(); await tx.rollback();
throw e; throw e;
} }