43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
|
|
describe('ticket getComponentsSum()', () => {
|
|
it('should get the list of component for the ticket sales', async() => {
|
|
const tx = await models.Ticket.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ticketId = 7;
|
|
const components = await models.Ticket.getComponentsSum(ticketId, options);
|
|
const length = components.length;
|
|
const anyComponent = components[Math.floor(Math.random() * Math.floor(length))];
|
|
|
|
expect(components.length).toBeGreaterThan(0);
|
|
expect(anyComponent.componentFk).toBeDefined();
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should return 0 if the given ticket does not have sales', async() => {
|
|
const tx = await models.Ticket.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ticketWithoutSales = 21;
|
|
const components = await models.Ticket.getComponentsSum(ticketWithoutSales, options);
|
|
|
|
expect(components.length).toEqual(0);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|