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

57 lines
1.7 KiB
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
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},
};
let ticketOne;
let ticketTwo;
beforeAll(async done => {
2020-10-08 14:00:19 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
try {
let originalTicketOne = await app.models.Ticket.findById(8);
let originalTicketTwo = await app.models.Ticket.findById(10);
originalTicketOne.id = null;
originalTicketTwo.id = null;
ticketOne = await app.models.Ticket.create(originalTicketOne);
ticketTwo = await app.models.Ticket.create(originalTicketTwo);
} catch (error) {
console.error(error);
}
done();
});
afterAll(async done => {
2020-10-08 14:00:19 +00:00
try {
await app.models.Ticket.destroyById(ticketOne.id);
await app.models.Ticket.destroyById(ticketTwo.id);
} catch (error) {
console.error(error);
}
done();
});
2020-06-18 11:50:52 +00:00
it('should return the state which has been applied to the given tickets', async() => {
let ctx = {req: {accessToken: {userId: 49}}};
let delivered = await app.models.State.findOne({where: {code: 'delivered'}, fields: ['id']});
let params = [ticketOne.id, ticketTwo.id];
2020-06-18 11:50:52 +00:00
let state = await app.models.TicketTracking.setDelivered(ctx, params);
2020-06-18 11:50:52 +00:00
expect(state.id).toEqual(delivered.id);
2020-10-08 14:00:19 +00:00
// restores
await app.models.TicketTracking.destroyById(state.id);
});
});