39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
const app = require('vn-loopback/server/server');
|
|
|
|
describe('Chat notifyIssue()', () => {
|
|
const ctx = {req: {accessToken: {userId: 1}}};
|
|
ctx.req.__ = value => {
|
|
return value;
|
|
};
|
|
const chatModel = app.models.Chat;
|
|
const departmentId = 31;
|
|
|
|
it(`should not call to the send() method and neither return a response`, async() => {
|
|
spyOn(chatModel, 'send').and.callThrough();
|
|
spyOn(chatModel, 'rawSql').and.returnValue([]);
|
|
|
|
const response = await chatModel.notifyIssues(ctx);
|
|
|
|
expect(chatModel.send).not.toHaveBeenCalled();
|
|
expect(response).toBeUndefined();
|
|
});
|
|
|
|
it(`should return a response calling the send() method`, async() => {
|
|
spyOn(chatModel, 'send').and.callThrough();
|
|
spyOn(chatModel, 'rawSql').and.returnValue([{title: 'Issue title'}]);
|
|
|
|
const department = await app.models.Department.findById(departmentId);
|
|
let orgChatName = department.chatName;
|
|
await department.updateAttribute('chatName', 'IT');
|
|
|
|
const response = await chatModel.notifyIssues(ctx);
|
|
|
|
expect(response.statusCode).toEqual(200);
|
|
expect(response.message).toEqual('Fake notification sent');
|
|
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', `@all ➔ There's a new urgent ticket`);
|
|
|
|
// restores
|
|
await department.updateAttribute('chatName', orgChatName);
|
|
});
|
|
});
|