2020-01-20 10:59:15 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
|
|
|
|
|
|
|
describe('chat sendCheckingPresence()', () => {
|
2020-10-06 08:15:27 +00:00
|
|
|
const today = new Date();
|
|
|
|
today.setHours(6, 0);
|
|
|
|
const ctx = {req: {accessToken: {userId: 1}}};
|
|
|
|
const chatModel = app.models.Chat;
|
2020-01-20 10:59:15 +00:00
|
|
|
const departmentId = 23;
|
|
|
|
const workerId = 107;
|
|
|
|
|
2020-10-06 08:15:27 +00:00
|
|
|
it(`should call send() method with the worker name if he's currently working then return a response`, async() => {
|
2020-01-20 10:59:15 +00:00
|
|
|
spyOn(chatModel, 'send').and.callThrough();
|
|
|
|
|
2020-10-06 08:15:27 +00:00
|
|
|
const timeEntry = await app.models.WorkerTimeControl.create({
|
|
|
|
userFk: workerId,
|
|
|
|
timed: today,
|
|
|
|
manual: false,
|
|
|
|
direction: 'in'
|
|
|
|
});
|
|
|
|
|
2020-01-20 10:59:15 +00:00
|
|
|
const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something');
|
|
|
|
|
|
|
|
expect(response.statusCode).toEqual(200);
|
|
|
|
expect(response.message).toEqual('Fake notification sent');
|
|
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '@HankPym', 'I changed something');
|
2020-10-06 08:15:27 +00:00
|
|
|
|
|
|
|
// restores
|
|
|
|
await app.models.WorkerTimeControl.destroyById(timeEntry.id);
|
2020-01-20 10:59:15 +00:00
|
|
|
});
|
|
|
|
|
2020-10-06 08:15:27 +00:00
|
|
|
it(`should call to send() method with the worker department channel if he's not currently working then return a response`, async() => {
|
2020-01-20 10:59:15 +00:00
|
|
|
spyOn(chatModel, 'send').and.callThrough();
|
|
|
|
|
|
|
|
const department = await app.models.Department.findById(departmentId);
|
|
|
|
await department.updateAttribute('chatName', 'cooler');
|
|
|
|
|
|
|
|
const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something');
|
|
|
|
|
|
|
|
expect(response.statusCode).toEqual(200);
|
|
|
|
expect(response.message).toEqual('Fake notification sent');
|
2020-10-22 05:49:04 +00:00
|
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something');
|
2020-01-20 10:59:15 +00:00
|
|
|
|
2020-10-06 08:15:27 +00:00
|
|
|
// restores
|
|
|
|
await department.updateAttribute('chatName', null);
|
2020-01-20 10:59:15 +00:00
|
|
|
});
|
|
|
|
});
|