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

53 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-12-21 11:50:28 +00:00
const app = require(`${serviceRoot}/server/server`);
2018-10-25 09:50:18 +00:00
describe('ticket changeState()', () => {
let ticket;
2018-11-06 12:59:16 +00:00
beforeAll(async () => {
2018-10-25 09:50:18 +00:00
let originalTicket = await app.models.Ticket.findOne({where: {id: 16}});
originalTicket.id = null;
ticket = await app.models.Ticket.create(originalTicket);
});
2018-11-06 12:59:16 +00:00
afterAll(async () => {
2018-10-25 09:50:18 +00:00
await app.models.Ticket.destroyById(ticket.id);
});
2018-11-06 12:59:16 +00:00
it('should throw an error if the ticket is not editable and the user isnt production', async () => {
let ctx = {req: {accessToken: {userId: 110}}};
let params = {ticketFk: 2, stateFk: 3};
let error;
try {
await app.models.TicketTracking.changeState(ctx, params);
} catch (e) {
error = e;
}
expect(error).toEqual(new Error(`You don't have enough privileges to change the state of this ticket`));
});
2018-11-06 12:59:16 +00:00
it('should be able to create a ticket tracking line for a not editable ticket if the user has the production role', async () => {
let ctx = {req: {accessToken: {userId: 50}}};
let params = {ticketFk: 20, stateFk: 3};
let res = await app.models.TicketTracking.changeState(ctx, params);
expect(res.__data.ticketFk).toBe(params.ticketFk);
expect(res.__data.stateFk).toBe(params.stateFk);
expect(res.__data.workerFk).toBe(50);
expect(res.__data.id).toBeDefined();
});
2018-11-06 12:59:16 +00:00
it('return an array with the created ticket tracking line', async () => {
let ctx = {req: {accessToken: {userId: 108}}};
2018-10-25 09:50:18 +00:00
let params = {ticketFk: ticket.id, stateFk: 3};
let res = await app.models.TicketTracking.changeState(ctx, params);
expect(res.__data.ticketFk).toBe(params.ticketFk);
expect(res.__data.stateFk).toBe(params.stateFk);
expect(res.__data.workerFk).toBe(110);
expect(res.__data.id).toBeDefined();
});
});