#569 ticket tracking back unit tests plus tiny refactor

This commit is contained in:
Carlos Jimenez 2018-08-07 11:06:40 +02:00
parent 3b3bc52b53
commit 9bd69baaf1
2 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1,24 @@
const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket model TicketTracking', () => {
let ticketTrackingId;
afterAll(async() => {
await app.models.TicketTracking.destroyById(ticketTrackingId);
});
it('should store the worker id into the instance', async() => {
let originalTrackings = await app.models.TicketTracking.find({where: {ticketFk: 1}});
expect(originalTrackings.length).toEqual(1);
await app.models.TicketTracking.create({ticketFk: 1, stateFk: 20});
let result = await app.models.TicketTracking.find({where: {ticketFk: 1}});
let workerFk = result[1].workerFk;
ticketTrackingId = result[1].id;
expect(result.length).toEqual(2);
expect(workerFk).toEqual(1);
});
});

View File

@ -6,9 +6,9 @@ module.exports = function(Self) {
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
let models = Self.app.models; let models = Self.app.models;
let token = ctx.options.accessToken; let token = ctx.options.accessToken;
let userId = token && token.userId; let currentUserId = token && token.userId;
let user = await models.Worker.findOne({where: {userFk: userId}}); let worker = await models.Worker.findOne({where: {userFk: currentUserId}});
ctx.instance.workerFk = user.id; ctx.instance.workerFk = worker.id;
}); });
}; };