#7896 - 24.36 Dev To Test #2884
|
@ -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));
|
||||
|
||||
if (!client)
|
||||
throw new Error(`Client with id ${clientId} not found`);
|
||||
|
||||
console.log('Client before update:', JSON.stringify(client, null, 2));
|
||||
console.log('Current hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
|
||||
|
||||
try {
|
||||
console.log('Attempting to update hasToInvoiceByAddress');
|
||||
const client = await models.Client.findById(clientId, null, options);
|
||||
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;
|
||||
|
||||
ctx.args = {
|
||||
clientId: clientId,
|
||||
invoiceDate: Date.vnNew(),
|
||||
maxShipped: Date.vnNew(),
|
||||
companyFk: companyFk,
|
||||
serialType: 'global'
|
||||
};
|
||||
|
||||
const invoiceOutId = await models.InvoiceOut.invoiceClient(ctx, options);
|
||||
|
||||
const invoiceOut = await models.InvoiceOut.findById(invoiceOutId, null, options);
|
||||
|
||||
expect(invoiceOutId).toBeGreaterThan(0);
|
||||
|
||||
const allClientTickets = await models.Ticket.find({
|
||||
where: {
|
||||
clientFk: clientId,
|
||||
or: [
|
||||
{refFk: null},
|
||||
{refFk: invoiceOut.ref}
|
||||
]
|
||||
}
|
||||
}, options);
|
||||
|
||||
console.log('Client after update:', JSON.stringify(client, null, 2));
|
||||
console.log('New hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue