Updated unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
0d8dffac30
commit
9d298c2a5e
|
@ -35,18 +35,16 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
async function sendMessage(sender, channel, message) {
|
||||
/* if (process.env.NODE_ENV !== 'production') {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
return new Promise(resolve => {
|
||||
return resolve({
|
||||
body: JSON.stringify(
|
||||
{statusCode: 200, message: 'Fake notification sent'}
|
||||
)
|
||||
statusCode: 200,
|
||||
message: 'Fake notification sent'
|
||||
});
|
||||
});
|
||||
}
|
||||
*/
|
||||
const login = await Self.getServiceAuth();
|
||||
|
||||
const login = await Self.getServiceAuth();
|
||||
const avatar = `${login.host}/avatar/${sender.name}`;
|
||||
|
||||
const options = {
|
||||
|
|
|
@ -44,7 +44,7 @@ module.exports = Self => {
|
|||
if (!recipient)
|
||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
|
||||
|
||||
const {data} = await getUserStatus(recipient.name);
|
||||
const {data} = await Self.getUserStatus(recipient.name);
|
||||
if (data) {
|
||||
if (data.status === 'offline') {
|
||||
// Send message to department room
|
||||
|
@ -69,7 +69,17 @@ module.exports = Self => {
|
|||
* @param {string} username - The recipient user name
|
||||
* @return {Promise} - The request promise
|
||||
*/
|
||||
async function getUserStatus(username) {
|
||||
Self.getUserStatus = async function getUserStatus(username) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
return new Promise(resolve => {
|
||||
return resolve({
|
||||
data: {
|
||||
status: 'online'
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const login = await Self.getServiceAuth();
|
||||
|
||||
const options = {
|
||||
|
@ -81,5 +91,5 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
return axios.get(`${login.api}/users.getStatus`, options);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,46 +1,62 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Chat sendCheckingPresence()', () => {
|
||||
const today = new Date();
|
||||
today.setHours(6, 0);
|
||||
const ctx = {req: {accessToken: {userId: 1}}};
|
||||
const chatModel = app.models.Chat;
|
||||
const chatModel = models.Chat;
|
||||
const departmentId = 23;
|
||||
const workerId = 1107;
|
||||
|
||||
it(`should call send() method with the worker name if he's currently working then return a response`, async() => {
|
||||
it(`should call to send() method with "@HankPym" as recipient argument`, async() => {
|
||||
spyOn(chatModel, 'send').and.callThrough();
|
||||
|
||||
const timeEntry = await app.models.WorkerTimeControl.create({
|
||||
userFk: workerId,
|
||||
timed: today,
|
||||
manual: false,
|
||||
direction: 'in'
|
||||
});
|
||||
spyOn(chatModel, 'getUserStatus').and.returnValue(
|
||||
new Promise(resolve => {
|
||||
return resolve({
|
||||
data: {
|
||||
status: 'online'
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const response = 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');
|
||||
|
||||
// restores
|
||||
await app.models.WorkerTimeControl.destroyById(timeEntry.id);
|
||||
});
|
||||
|
||||
it(`should call to send() method with the worker department channel if he's not currently working then return a response`, async() => {
|
||||
it(`should call to send() method with "#cooler" as recipient argument`, async() => {
|
||||
spyOn(chatModel, 'send').and.callThrough();
|
||||
spyOn(chatModel, 'getUserStatus').and.returnValue(
|
||||
new Promise(resolve => {
|
||||
return resolve({
|
||||
data: {
|
||||
status: 'offline'
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
const department = await app.models.Department.findById(departmentId);
|
||||
await department.updateAttribute('chatName', 'cooler');
|
||||
const tx = await models.Claim.beginTransaction({});
|
||||
|
||||
const response = await chatModel.sendCheckingPresence(ctx, workerId, 'I changed something');
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response.message).toEqual('Fake notification sent');
|
||||
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#cooler', '@HankPym ➔ I changed something');
|
||||
const department = await models.Department.findById(departmentId, null, options);
|
||||
await department.updateAttribute('chatName', 'cooler');
|
||||
|
||||
// restores
|
||||
await department.updateAttribute('chatName', null);
|
||||
const response = 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');
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -57,7 +57,7 @@ describe('Claim createFromSales()', () => {
|
|||
const todayMinusEightDays = new Date();
|
||||
todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8);
|
||||
|
||||
const ticket = await models.Ticket.findById(ticketId, options);
|
||||
const ticket = await models.Ticket.findById(ticketId, null, options);
|
||||
await ticket.updateAttribute('landed', todayMinusEightDays, options);
|
||||
|
||||
const claim = await models.Claim.createFromSales(ctx, ticketId, newSale, options);
|
||||
|
@ -88,7 +88,7 @@ describe('Claim createFromSales()', () => {
|
|||
const todayMinusEightDays = new Date();
|
||||
todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8);
|
||||
|
||||
const ticket = await models.Ticket.findById(ticketId, options);
|
||||
const ticket = await models.Ticket.findById(ticketId, null, options);
|
||||
await ticket.updateAttribute('landed', todayMinusEightDays, options);
|
||||
|
||||
await models.Claim.createFromSales(ctx, ticketId, newSale, options);
|
||||
|
|
|
@ -35,7 +35,7 @@ describe('Client updateFiscalData', () => {
|
|||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const client = await models.Client.findById(clientId, options);
|
||||
const client = await models.Client.findById(clientId, null, options);
|
||||
await client.updateAttribute('isTaxDataChecked', false, options);
|
||||
|
||||
const ctx = {req: {accessToken: {userId: salesAssistantId}}};
|
||||
|
|
Loading…
Reference in New Issue