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

59 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-02-23 11:07:05 +00:00
const models = require('vn-loopback/server/server').models;
2020-01-20 10:59:15 +00:00
2021-02-01 08:29:47 +00:00
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}}};
2022-02-23 11:07:05 +00:00
const chatModel = models.Chat;
2020-01-20 10:59:15 +00:00
const departmentId = 23;
const workerId = 1107;
2020-01-20 10:59:15 +00:00
2022-02-23 11:07:05 +00:00
it(`should call to send() method with "@HankPym" as recipient argument`, async() => {
2020-01-20 10:59:15 +00:00
spyOn(chatModel, 'send').and.callThrough();
2022-02-23 11:07:05 +00:00
spyOn(chatModel, 'getUserStatus').and.returnValue(
new Promise(resolve => {
return resolve({
data: {
status: 'online'
}
});
})
);
2020-10-06 08:15:27 +00:00
2022-04-11 12:43:20 +00:00
await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something');
2020-01-20 10:59:15 +00:00
expect(chatModel.send).toHaveBeenCalledWith(ctx, '@HankPym', 'I changed something');
});
2022-02-23 11:07:05 +00:00
it(`should call to send() method with "#cooler" as recipient argument`, async() => {
2020-01-20 10:59:15 +00:00
spyOn(chatModel, 'send').and.callThrough();
2022-02-23 11:07:05 +00:00
spyOn(chatModel, 'getUserStatus').and.returnValue(
new Promise(resolve => {
return resolve({
data: {
status: 'offline'
}
});
})
);
const tx = await models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
const department = await models.Department.findById(departmentId, null, options);
await department.updateAttribute('chatName', 'cooler');
2022-04-11 12:43:20 +00:00
await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something');
2022-02-23 11:07:05 +00:00
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something');
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
2020-01-20 10:59:15 +00:00
});
});