Tarea #567 /ticket-tracking/changeState.js Backend unit tests
This commit is contained in:
parent
48670b9724
commit
8d1cf0c02f
|
@ -8,7 +8,7 @@ module.exports = Self => {
|
|||
arg: 'params',
|
||||
type: 'object',
|
||||
required: true,
|
||||
description: 'ticketFk',
|
||||
description: 'ticketFk, stateFk',
|
||||
http: {source: 'body'}
|
||||
}],
|
||||
returns: {
|
||||
|
@ -29,6 +29,7 @@ module.exports = Self => {
|
|||
if (ctx.req.accessToken) {
|
||||
let token = ctx.req.accessToken;
|
||||
let currentUserId = token && token.userId;
|
||||
console.log(currentUserId);
|
||||
isProduction = await models.Account.hasRole(currentUserId, 'Production');
|
||||
let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
|
||||
params.workerFk = worker.id;
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
const app = require(`${servicesDir}/ticket/server/server`);
|
||||
|
||||
describe('ticket listSaleTracking()', () => {
|
||||
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`));
|
||||
});
|
||||
|
||||
it('should be able to create a ticket tracking line for a not editable ticket if the user has te 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();
|
||||
});
|
||||
|
||||
it('return an array with the created ticket tracking line', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 108}}};
|
||||
let params = {ticketFk: 1, 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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue