#7896 - 24.36 Dev To Test #2884
|
@ -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);
|
|
||||||
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');
|
|
||||||
await client.updateAttribute('hasToInvoiceByAddress', false, options);
|
await client.updateAttribute('hasToInvoiceByAddress', false, options);
|
||||||
console.log('Update successful');
|
|
||||||
} catch (updateError) {
|
ctx.args = {
|
||||||
console.error('Error updating hasToInvoiceByAddress:', updateError);
|
clientId: clientId,
|
||||||
console.error('Error stack:', updateError.stack);
|
invoiceDate: Date.vnNew(),
|
||||||
throw updateError;
|
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));
|
const billedTickets = await models.Ticket.find({
|
||||||
console.log('New hasToInvoiceByAddress value:', client.hasToInvoiceByAddress);
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue