salix/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-03-26 11:40:44 +00:00
const {models} = require('vn-loopback/server/server');
describe('ticketCollection hasUncheckedTicket()', () => {
2024-03-27 06:26:11 +00:00
it('should return false because there are not tickets not checked', async() => {
2024-03-26 11:40:44 +00:00
const ticketFk = 1;
const result = await models.TicketCollection.hasUncheckedTicket(ticketFk);
expect(result).toBe(false);
});
it('should return true because there is a ticket not checked', async() => {
const ticketFk = 1;
2024-03-27 06:26:11 +00:00
const stateFkCurrent = 16;
const stateFkUpdated = 7;
2024-03-26 11:40:44 +00:00
const tx = await models.TicketTracking.beginTransaction({});
const myOptions = {transaction: tx};
const filter = {where: {
ticketFk: 1,
2024-03-27 06:26:11 +00:00
stateFk: stateFkCurrent}
2024-03-26 11:40:44 +00:00
};
try {
const ticketTracking = await models.TicketTracking.findOne(filter, myOptions);
await ticketTracking.updateAttributes({
2024-03-27 06:26:11 +00:00
stateFk: stateFkUpdated
2024-03-28 07:08:32 +00:00
}, myOptions);
2024-03-26 11:40:44 +00:00
const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions);
expect(result).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});
2024-03-28 07:08:32 +00:00