salix/modules/ticket/back/methods/sale/specs/refund.spec.js

79 lines
2.3 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
2023-02-16 09:45:13 +00:00
describe('Sale refund()', () => {
const userId = 5;
const activeCtx = {
accessToken: {userId: userId},
};
2022-04-26 11:25:12 +00:00
const servicesIds = [3];
beforeEach(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
it('should create ticket with the selected lines', async() => {
const tx = await models.Sale.beginTransaction({});
const salesIds = [7, 8];
try {
const options = {transaction: tx};
2023-04-24 06:57:10 +00:00
const refundedTicket = await models.Sale.refund(salesIds, servicesIds, false, options);
2023-04-24 06:57:10 +00:00
expect(refundedTicket).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
2023-04-24 06:57:10 +00:00
it('should create one ticket for each unique ticketFk in the sales', async() => {
const tx = await models.Sale.beginTransaction({});
const salesIds = [6, 7];
try {
const options = {transaction: tx};
2023-02-16 09:45:13 +00:00
const createSingleTicket = false;
2023-04-24 06:57:10 +00:00
const ticket = await models.Sale.refund(salesIds, servicesIds, createSingleTicket, options);
2023-04-24 06:57:10 +00:00
const refundedTicket = await models.Ticket.findOne({
where: {
2023-04-24 06:57:10 +00:00
id: ticket.id
},
include: [
{
relation: 'ticketSales',
scope: {
include: {
relation: 'components'
}
}
},
{
relation: 'ticketServices',
}
]
}, options);
2023-04-24 06:57:10 +00:00
const salesLength = refundedTicket.ticketSales().length;
const componentsLength = refundedTicket.ticketSales()[0].components().length;
2023-04-24 06:57:10 +00:00
expect(refundedTicket).toBeDefined();
expect(salesLength).toEqual(2);
expect(componentsLength).toEqual(4);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});