salix/modules/ticket/back/methods/ticket-tracking/specs/setDelivered.spec.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
2020-10-08 14:00:19 +00:00
const LoopBackContext = require('loopback-context');
describe('ticket setDelivered()', () => {
2020-10-08 14:00:19 +00:00
const userId = 50;
const activeCtx = {
accessToken: {userId: userId},
};
beforeAll(async done => {
2020-10-08 14:00:19 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
done();
});
it('should return the state which has been applied to the given tickets', async() => {
const tx = await models.TicketTracking.beginTransaction({});
2020-10-08 14:00:19 +00:00
try {
const options = {transaction: tx};
const ctx = {req: {accessToken: {userId: 49}}};
const originalTicketOne = await models.Ticket.findById(8, null, options);
const originalTicketTwo = await models.Ticket.findById(10, null, options);
originalTicketOne.id = null;
originalTicketTwo.id = null;
const ticketOne = await models.Ticket.create(originalTicketOne, options);
const ticketTwo = await models.Ticket.create(originalTicketTwo, options);
const delivered = await models.State.findOne({where: {code: 'delivered'}, fields: ['id']}, options);
const params = [ticketOne.id, ticketTwo.id];
const state = await models.TicketTracking.setDelivered(ctx, params, options);
2020-10-08 14:00:19 +00:00
expect(state.id).toEqual(delivered.id);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});