2021-10-07 07:57:07 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2020-10-08 14:00:19 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
2020-06-17 13:38:37 +00:00
|
|
|
|
|
|
|
describe('ticket setDelivered()', () => {
|
2020-10-08 14:00:19 +00:00
|
|
|
const userId = 50;
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: userId},
|
|
|
|
};
|
|
|
|
|
2020-06-17 13:38:37 +00:00
|
|
|
beforeAll(async done => {
|
2020-10-08 14:00:19 +00:00
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
2020-06-17 13:38:37 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
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 {
|
2021-10-07 07:57:07 +00:00
|
|
|
const options = {transaction: tx};
|
2020-06-17 13:38:37 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
const ctx = {req: {accessToken: {userId: 49}}};
|
2020-06-17 13:38:37 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
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);
|
2020-06-17 13:38:37 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
const delivered = await models.State.findOne({where: {code: 'delivered'}, fields: ['id']}, options);
|
2020-06-17 13:38:37 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
const params = [ticketOne.id, ticketTwo.id];
|
|
|
|
const state = await models.TicketTracking.setDelivered(ctx, params, options);
|
2020-10-08 14:00:19 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
expect(state.id).toEqual(delivered.id);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2020-06-17 13:38:37 +00:00
|
|
|
});
|
|
|
|
});
|