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

This commit is contained in:
Joan Sanchez 2021-04-12 08:02:35 +02:00
commit de769a2565
6 changed files with 48 additions and 11 deletions

View File

@ -15,15 +15,21 @@ module.exports = Self => {
Self.notifyIssues = async ctx => { Self.notifyIssues = async ctx => {
const models = Self.app.models; const models = Self.app.models;
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
const [urgentIssue] = await Self.rawSql(` const tickets = await models.OsTicket.rawSql(`
SELECT * FROM managedesktop.vn_workOrderInmediata LIMIT 1 SELECT t.ticket_id AS id, t.number, ua.username, td.subject
FROM ost_ticket t
JOIN ost_user_account ua ON t.user_id = ua.user_id
JOIN ost_ticket__cdata td ON t.ticket_id = td.ticket_id
JOIN ost_ticket_priority tp ON td.priority = tp.priority_id
WHERE tp.priority = 'emergency' AND t.staff_id = 0
`); `);
if (!urgentIssue) return; if (!tickets.length) return;
const message = $t(`There's a new urgent ticket`, { let message = $t(`There's a new urgent ticket:`);
title: urgentIssue.title, const ostUri = 'https://cau.verdnatura.es/scp/tickets.php?id=';
issueId: urgentIssue.workOrderId tickets.forEach(ticket => {
message += `\r\n[ID: *${ticket.number}* - ${ticket.subject} (@${ticket.username})](${ostUri + ticket.id})`;
}); });
const department = await models.Department.findOne({ const department = await models.Department.findOne({

View File

@ -6,11 +6,12 @@ describe('Chat notifyIssue()', () => {
return value; return value;
}; };
const chatModel = app.models.Chat; const chatModel = app.models.Chat;
const osTicketModel = app.models.OsTicket;
const departmentId = 31; const departmentId = 31;
it(`should not call to the send() method and neither return a response`, async() => { it(`should not call to the send() method and neither return a response`, async() => {
spyOn(chatModel, 'send').and.callThrough(); spyOn(chatModel, 'send').and.callThrough();
spyOn(chatModel, 'rawSql').and.returnValue([]); spyOn(osTicketModel, 'rawSql').and.returnValue([]);
const response = await chatModel.notifyIssues(ctx); const response = await chatModel.notifyIssues(ctx);
@ -20,7 +21,13 @@ describe('Chat notifyIssue()', () => {
it(`should return a response calling the send() method`, async() => { it(`should return a response calling the send() method`, async() => {
spyOn(chatModel, 'send').and.callThrough(); spyOn(chatModel, 'send').and.callThrough();
spyOn(chatModel, 'rawSql').and.returnValue([{title: 'Issue title'}]); spyOn(osTicketModel, 'rawSql').and.returnValue([{
id: 1,
number: '00001',
username: 'batman',
subject: 'Issue title'}
]);
const expectedMessage = `@all ➔ There's a new urgent ticket:\r\n[ID: *00001* - Issue title (@batman)](https://osticket.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;
@ -30,7 +37,7 @@ describe('Chat notifyIssue()', () => {
expect(response.statusCode).toEqual(200); expect(response.statusCode).toEqual(200);
expect(response.message).toEqual('Fake notification sent'); expect(response.message).toEqual('Fake notification sent');
expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', `@all ➔ There's a new urgent ticket`); expect(chatModel.send).toHaveBeenCalledWith(ctx, '#IT', expectedMessage);
// restores // restores
await department.updateAttribute('chatName', orgChatName); await department.updateAttribute('chatName', orgChatName);

View File

@ -94,6 +94,9 @@
}, },
"Warehouse": { "Warehouse": {
"dataSource": "vn" "dataSource": "vn"
},
"OsTicket": {
"dataSource": "osticket"
} }
} }

12
back/models/osticket.json Normal file
View File

@ -0,0 +1,12 @@
{
"name": "OsTicket",
"base": "VnModel",
"acls": [{
"property": "validations",
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}]
}

View File

@ -173,7 +173,7 @@
"Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío", "Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
"This BIC already exist.": "Este BIC ya existe.", "This BIC already exist.": "Este BIC ya existe.",
"That item doesn't exists": "Ese artículo no existe", "That item doesn't exists": "Ese artículo no existe",
"There's a new urgent ticket": "Hay un nuevo ticket urgente: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", "There's a new urgent ticket:": "Hay un nuevo ticket urgente:",
"Invalid account": "Cuenta inválida", "Invalid account": "Cuenta inválida",
"Compensation account is empty": "La cuenta para compensar está vacia", "Compensation account is empty": "La cuenta para compensar está vacia",
"This genus already exist": "Este genus ya existe", "This genus already exist": "Este genus ya existe",

View File

@ -17,6 +17,15 @@
"connectTimeout": 40000, "connectTimeout": 40000,
"acquireTimeout": 20000 "acquireTimeout": 20000
}, },
"osticket": {
"connector": "vn-mysql",
"database": "vn",
"debug": false,
"host": "localhost",
"port": "3306",
"username": "root",
"password": "root"
},
"tempStorage": { "tempStorage": {
"name": "tempStorage", "name": "tempStorage",
"connector": "loopback-component-storage", "connector": "loopback-component-storage",