Updated RocketChat unit tests
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2022-04-11 14:43:20 +02:00
parent 255086c7e6
commit 99499b214e
3 changed files with 7 additions and 14 deletions

View File

@ -13,10 +13,9 @@ describe('Chat notifyIssue()', () => {
spyOn(chatModel, 'send').and.callThrough(); spyOn(chatModel, 'send').and.callThrough();
spyOn(osTicketModel, 'rawSql').and.returnValue([]); spyOn(osTicketModel, 'rawSql').and.returnValue([]);
const response = await chatModel.notifyIssues(ctx); await chatModel.notifyIssues(ctx);
expect(chatModel.send).not.toHaveBeenCalled(); expect(chatModel.send).not.toHaveBeenCalled();
expect(response).toBeUndefined();
}); });
it(`should return a response calling the send() method`, async() => { it(`should return a response calling the send() method`, async() => {
@ -27,16 +26,15 @@ describe('Chat notifyIssue()', () => {
username: 'batman', username: 'batman',
subject: 'Issue title'} subject: 'Issue title'}
]); ]);
// eslint-disable-next-line max-len
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)`; 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)`;
const department = await app.models.Department.findById(departmentId); const department = await app.models.Department.findById(departmentId);
let orgChatName = department.chatName; let orgChatName = department.chatName;
await department.updateAttribute('chatName', 'IT'); await department.updateAttribute('chatName', 'IT');
const response = await chatModel.notifyIssues(ctx); await chatModel.notifyIssues(ctx);
expect(response.statusCode).toEqual(200);
expect(response.message).toEqual('Fake notification sent');
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', expectedMessage); expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', expectedMessage);
// restores // restores

View File

@ -5,14 +5,13 @@ describe('Chat send()', () => {
let ctx = {req: {accessToken: {userId: 1}}}; let ctx = {req: {accessToken: {userId: 1}}};
let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something'); let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something');
expect(response.statusCode).toEqual(200); expect(response).toEqual(true);
expect(response.message).toEqual('Fake notification sent');
}); });
it('should retrun false as response', async() => { it('should retrun false as response', async() => {
let ctx = {req: {accessToken: {userId: 18}}}; let ctx = {req: {accessToken: {userId: 18}}};
let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something'); let response = await app.models.Chat.send(ctx, '@salesPerson', 'I changed something');
expect(response).toBeFalsy(); expect(response).toEqual(false);
}); });
}); });

View File

@ -20,10 +20,8 @@ describe('Chat sendCheckingPresence()', () => {
}) })
); );
const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something'); 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'); expect(chatModel.send).toHaveBeenCalledWith(ctx, '@HankPym', 'I changed something');
}); });
@ -47,10 +45,8 @@ describe('Chat sendCheckingPresence()', () => {
const department = await models.Department.findById(departmentId, null, options); const department = await models.Department.findById(departmentId, null, options);
await department.updateAttribute('chatName', 'cooler'); await department.updateAttribute('chatName', 'cooler');
const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something'); 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, '#cooler', '@HankPym ➔ I changed something'); expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something');
await tx.rollback(); await tx.rollback();