2024-01-23 11:13:23 +00:00
|
|
|
const {models} = require('vn-loopback/server/server');
|
|
|
|
|
2024-01-23 14:58:09 +00:00
|
|
|
describe('collection getSalesFromTicketOrCollection()', () => {
|
2024-01-23 11:13:23 +00:00
|
|
|
const collectionOrTicketFk = 999999;
|
|
|
|
const print = true;
|
|
|
|
const source = 'CHECKER';
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
ctx = {
|
|
|
|
req: {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
headers: {origin: 'http://localhost'},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
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 {
|
|
|
|
const collection = await models.Collection.getSalesFromTicketOrCollection(ctx,
|
|
|
|
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};
|
|
|
|
try {
|
|
|
|
const printQueueBefore = await models.Collection.rawSql('SELECT * FROM printQueue', [], options);
|
|
|
|
await models.Collection.getSalesFromTicketOrCollection(ctx,
|
|
|
|
collectionOrTicketFk, print, source, options);
|
|
|
|
const printQueueAfter = await models.Collection.rawSql('SELECT * FROM printQueue', [], options);
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|