Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into test
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-02-11 09:45:55 +01:00
commit 9c419c8863
3 changed files with 7 additions and 10 deletions

View File

@ -31,7 +31,7 @@ module.exports = Self => {
const recipient = to.replace('@', '');
if (sender.name != recipient)
return sendMessage(sender, to, `@${sender.name}: ${message} `);
return sendMessage(sender, to, message);
};
async function sendMessage(sender, channel, message) {
@ -42,10 +42,12 @@ module.exports = Self => {
return sendAuth(uri, {
'channel': channel,
'avatar': avatar,
'alias': sender.nickname,
'text': message
}).catch(async error => {
if (error.statusCode === 401 && !this.resendAttempted) {
this.resendAttempted = true;
this.auth = null;
return sendMessage(sender, channel, message);
}

View File

@ -30,10 +30,7 @@ module.exports = Self => {
const query = `SELECT worker_isWorking(?) isWorking`;
const [result] = await Self.rawSql(query, [workerId]);
let room;
if (result.isWorking)
room = `@${account.name}`;
else {
if (!result.isWorking) {
const workerDepartment = await models.WorkerDepartment.findById(workerId, {
include: {
relation: 'department'
@ -41,13 +38,11 @@ module.exports = Self => {
});
const department = workerDepartment.department();
const channelName = department.chatName;
room = `#${channelName}`;
if (channelName)
room = `#${channelName}`;
else room = `@${account.name}`;
return Self.send(ctx, `#${channelName}`, `@${account.name} => ${message}`);
}
return Self.send(ctx, room, message);
return Self.send(ctx, `@${account.name}`, message);
};
};

View File

@ -38,7 +38,7 @@ describe('chat sendCheckingPresence()', () => {
expect(response.statusCode).toEqual(200);
expect(response.message).toEqual('Fake notification sent');
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', 'I changed something');
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym => I changed something');
});
it(`should call to send() method with the worker username when the worker is working`, async() => {