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

39 lines
1.2 KiB
JavaScript

const {models} = require('vn-loopback/server/server');
describe('ticketCollection hasUncheckedTicket()', () => {
it('should return false because there are not tickets not checked', async() => {
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;
const stateFkCurrent = 16;
const stateFkUpdated = 7;
const tx = await models.TicketTracking.beginTransaction({});
const myOptions = {transaction: tx};
const filter = {where: {
ticketFk: 1,
stateFk: stateFkCurrent}
};
try {
const ticketTracking = await models.TicketTracking.findOne(filter, myOptions);
await ticketTracking.updateAttributes({
stateFk: stateFkUpdated
}, myOptions);
const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions);
expect(result).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});