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

44 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2023-01-24 08:04:43 +00:00
const {models} = require('vn-loopback/server/server');
2021-02-01 08:29:47 +00:00
describe('Chat notifyIssue()', () => {
const ctx = {req: {accessToken: {userId: 1}}};
ctx.req.__ = value => {
return value;
};
2023-01-24 08:04:43 +00:00
const chatModel = models.Chat;
const osTicketModel = 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
2023-01-24 08:04:43 +00:00
const department = await models.Department.findById(departmentId);
2021-02-01 08:29:47 +00:00
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);
});
});