salix/back/methods/chat/spec/notifyIssue.spec.js

44 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-02-01 08:29:47 +00:00
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;
2021-04-12 05:48:29 +00:00
const osTicketModel = app.models.OsTicket;
2021-02-01 08:29:47 +00:00
const departmentId = 31;
2021-02-02 07:15:20 +00:00
it(`should not call to the send() method and neither return a response`, async() => {
spyOn(chatModel, 'send').and.callThrough();
2021-04-12 05:48:29 +00:00
spyOn(osTicketModel, 'rawSql').and.returnValue([]);
2021-02-02 07:15:20 +00:00
2022-04-11 12:43:20 +00:00
await chatModel.notifyIssues(ctx);
2021-02-02 07:15:20 +00:00
expect(chatModel.send).not.toHaveBeenCalled();
});
it(`should return a response calling the send() method`, async() => {
2021-02-01 08:29:47 +00:00
spyOn(chatModel, 'send').and.callThrough();
2021-04-12 05:48:29 +00:00
spyOn(osTicketModel, 'rawSql').and.returnValue([{
id: 1,
number: '00001',
username: 'batman',
subject: 'Issue title'}
]);
2022-04-11 12:43:20 +00:00
// eslint-disable-next-line max-len
2022-11-25 11:56:25 +00:00
const expectedMessage = `@all ➔ There's a new urgent ticket:\r\n[ID: 00001 - Issue title @batman](https://cau.verdnatura.es/scp/tickets.php?id=1)`;
2021-02-01 08:29:47 +00:00
const department = await app.models.Department.findById(departmentId);
let orgChatName = department.chatName;
await department.updateAttribute('chatName', 'IT');
2022-04-11 12:43:20 +00:00
await chatModel.notifyIssues(ctx);
2021-02-01 08:29:47 +00:00
2021-04-12 05:48:29 +00:00
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', expectedMessage);
2021-02-01 08:29:47 +00:00
// restores
await department.updateAttribute('chatName', orgChatName);
});
});