2024-01-23 11:13:23 +00:00
|
|
|
const {models} = require('vn-loopback/server/server');
|
|
|
|
|
2024-02-19 13:46:42 +00:00
|
|
|
describe('collection getSales()', () => {
|
2024-01-23 11:13:23 +00:00
|
|
|
const collectionOrTicketFk = 999999;
|
|
|
|
const print = true;
|
|
|
|
const source = 'CHECKER';
|
2024-06-14 06:39:57 +00:00
|
|
|
const ctx = beforeAll.getCtx();
|
2024-01-23 11:13:23 +00:00
|
|
|
|
|
|
|
it('should return a collection with tickets, placements and barcodes settled correctly', async() => {
|
2024-01-23 14:58:09 +00:00
|
|
|
const tx = await models.Collection.beginTransaction({});
|
|
|
|
const options = {transaction: tx};
|
|
|
|
try {
|
2024-02-19 13:46:42 +00:00
|
|
|
const collection = await models.Collection.getSales(ctx,
|
2024-01-23 14:58:09 +00:00
|
|
|
collectionOrTicketFk, print, source, options);
|
2024-01-23 11:13:23 +00:00
|
|
|
|
2024-01-23 14:58:09 +00:00
|
|
|
const [firstTicket] = collection.tickets;
|
|
|
|
const [firstSale] = firstTicket.sales;
|
|
|
|
const [firstPlacement] = firstSale.placements;
|
2024-01-23 11:13:23 +00:00
|
|
|
|
2024-01-23 14:58:09 +00:00
|
|
|
expect(collection.tickets.length).toBeTruthy();
|
|
|
|
expect(collection.collectionFk).toEqual(firstTicket.ticketFk);
|
2024-01-23 11:13:23 +00:00
|
|
|
|
2024-01-23 14:58:09 +00:00
|
|
|
expect(firstSale.ticketFk).toEqual(firstTicket.ticketFk);
|
|
|
|
expect(firstSale.placements.length).toBeTruthy();
|
|
|
|
expect(firstSale.barcodes.length).toBeTruthy();
|
2024-01-23 11:13:23 +00:00
|
|
|
|
2024-01-23 14:58:09 +00:00
|
|
|
expect(firstSale.saleFk).toEqual(firstPlacement.saleFk);
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should print a sticker', async() => {
|
|
|
|
const tx = await models.Collection.beginTransaction({});
|
|
|
|
const options = {transaction: tx};
|
2024-01-25 07:13:47 +00:00
|
|
|
const query = 'SELECT * FROM printQueue pq JOIN printQueueArgs pqa ON pqa.printQueueFk = pq.id';
|
2024-01-23 14:58:09 +00:00
|
|
|
try {
|
2024-01-25 07:13:47 +00:00
|
|
|
const printQueueBefore = await models.Collection.rawSql(
|
|
|
|
query, [], options);
|
2024-02-19 13:46:42 +00:00
|
|
|
await models.Collection.getSales(ctx,
|
2024-01-25 07:13:47 +00:00
|
|
|
collectionOrTicketFk, true, source, options);
|
|
|
|
const printQueueAfter = await models.Collection.rawSql(
|
|
|
|
query, [], options);
|
2024-01-23 14:58:09 +00:00
|
|
|
|
|
|
|
expect(printQueueAfter.length).toEqual(printQueueBefore.length + 1);
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2024-01-23 11:13:23 +00:00
|
|
|
});
|
|
|
|
});
|