testback arreglados
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2020-10-30 15:50:59 +01:00
parent 71fe677a7e
commit b50ae7b8ca
5 changed files with 65 additions and 34 deletions

View File

@ -0,0 +1,25 @@
DROP TRIGGER IF EXISTS `vn`.`ticket_afterUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` TRIGGER `ticket_afterUpdate`
AFTER UPDATE ON `ticket`
FOR EACH ROW
BEGIN
IF !(NEW.id <=> OLD.id)
OR !(NEW.warehouseFk <=> OLD.warehouseFk)
OR !(NEW.shipped <=> OLD.shipped) THEN
CALL stock.log_add('ticket', NEW.id, OLD.id);
END IF;
IF NEW.clientFk = 2067 AND !(NEW.clientFk <=> OLD.clientFk) THEN
-- Fallo que se insertan no se sabe como tickets en este cliente
INSERT INTO vn.mail SET
`sender` = 'jgallego@verdnatura.es',
`replyTo` = 'jgallego@verdnatura.es',
`subject` = 'Modificado ticket al cliente 2067',
`body` = CONCAT(account.myUserGetName(), ' ha modificado el ticket ',
NEW.id);
END IF;
END$$
DELIMITER ;

View File

@ -325,7 +325,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr
(119, 'address 19', 'Somewhere in Alberic', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0), (119, 'address 19', 'Somewhere in Alberic', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0),
(120, 'address 20', 'Somewhere in Montortal', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0), (120, 'address 20', 'Somewhere in Montortal', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0),
(121, 'address 21', 'the bat cave', 'Silla', 46460, 1, 1111111111, 222222222, 1, 101, 2, NULL, NULL, 0, 0), (121, 'address 21', 'the bat cave', 'Silla', 46460, 1, 1111111111, 222222222, 1, 101, 2, NULL, NULL, 0, 0),
(122, 'address 22', 'NY roofs', 'Silla', 46460, 1, 1111111111, 222222222, 1, 102, 2, NULL, NULL, 0, 0), (122, 'NY roofs', 'address 22', 'Silla', 46460, 1, 1111111111, 222222222, 1, 102, 2, NULL, NULL, 0, 0),
(123, 'address 23', 'The phone box', 'Silla', 46460, 1, 1111111111, 222222222, 1, 103, 2, NULL, NULL, 0, 0), (123, 'address 23', 'The phone box', 'Silla', 46460, 1, 1111111111, 222222222, 1, 103, 2, NULL, NULL, 0, 0),
(124, 'address 24', 'Stark tower Silla', 'Silla', 46460, 1, 1111111111, 222222222, 1, 104, 2, NULL, NULL, 0, 0), (124, 'address 24', 'Stark tower Silla', 'Silla', 46460, 1, 1111111111, 222222222, 1, 104, 2, NULL, NULL, 0, 0),
(125, 'address 25', 'The plastic cell', 'Silla', 46460, 1, 1111111111, 222222222, 1, 105, 2, NULL, NULL, 0, 0), (125, 'address 25', 'The plastic cell', 'Silla', 46460, 1, 1111111111, 222222222, 1, 105, 2, NULL, NULL, 0, 0),

View File

@ -1,82 +1,84 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('ticket-request filter()', () => { describe('ticket-request filter()', () => {
it('should now return all ticket requests', async() => { const userId = 9;
let ctx = {req: {accessToken: {userId: 9}}, args: {}}; let ctx = {req: {accessToken: {userId: userId}}};
let result = await app.models.TicketRequest.filter(ctx); it('should now return all ticket requests', async() => {
ctx.args = {};
const result = await app.models.TicketRequest.filter(ctx);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
}); });
it('should return the ticket request matching a generic search value which is the ticket ID', async() => { it('should return the ticket request matching a generic search value which is the ticket ID', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {search: 11}}; ctx.args = {search: 11};
let result = await app.models.TicketRequest.filter(ctx); const result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(4); expect(requestId).toEqual(4);
}); });
it('should return the ticket request matching a generic search value which is the client address alias', async() => { it('should return the ticket request matching a generic search value which is the client address alias', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {search: 'NY roofs'}}; ctx.args = {search: 'NY roofs'};
let result = await app.models.TicketRequest.filter(ctx); const result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(4); expect(requestId).toEqual(4);
}); });
it('should return the ticket request matching the ticket ID', async() => { it('should return the ticket request matching the ticket ID', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {ticketFk: 11}}; ctx.args = {ticketFk: 11};
const result = await app.models.TicketRequest.filter(ctx);
let result = await app.models.TicketRequest.filter(ctx); const requestId = result[0].id;
let requestId = result[0].id;
expect(requestId).toEqual(4); expect(requestId).toEqual(4);
}); });
it('should return the ticket request matching the atender ID', async() => { it('should return the ticket request matching the atender ID', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {attenderFk: 35}}; ctx.args = {attenderFk: 35};
let result = await app.models.TicketRequest.filter(ctx); const result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(3); expect(requestId).toEqual(3);
}); });
it('should return the ticket request matching the isOk triple-state', async() => { it('should return the ticket request matching the isOk triple-state', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {isOk: null}}; ctx.args = {isOk: null};
let result = await app.models.TicketRequest.filter(ctx); const result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(3); expect(requestId).toEqual(3);
}); });
it('should return the ticket request matching the client ID', async() => { it('should return the ticket request matching the client ID', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {clientFk: 102}}; ctx.args = {clientFk: 102};
let result = await app.models.TicketRequest.filter(ctx); const result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(4); expect(requestId).toEqual(4);
}); });
it('should return the ticket request matching the warehouse ID', async() => { it('should return the ticket request matching the warehouse ID', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {warehouse: 1}}; ctx.args = {warehouse: 1};
let result = await app.models.TicketRequest.filter(ctx, {order: 'id'}); const result = await app.models.TicketRequest.filter(ctx, {order: 'id'});
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(3); expect(requestId).toEqual(3);
}); });
it('should return the ticket request matching the salesPerson ID', async() => { it('should return the ticket request matching the salesPerson ID', async() => {
let ctx = {req: {accessToken: {userId: 9}}, args: {salesPersonFk: 18}}; ctx.args = {salesPersonFk: 18};
let result = await app.models.TicketRequest.filter(ctx); const result = await app.models.TicketRequest.filter(ctx);
let requestId = result[0].id; const requestId = result[0].id;
expect(requestId).toEqual(3); expect(requestId).toEqual(3);
}); });

View File

@ -92,6 +92,7 @@ module.exports = Self => {
const observationTypeDelivery = await models.ObservationType.findOne({ const observationTypeDelivery = await models.ObservationType.findOne({
where: {code: 'delivery'} where: {code: 'delivery'}
}); });
const originalTicket = await models.Ticket.findOne({ const originalTicket = await models.Ticket.findOne({
where: {id: id}, where: {id: id},
fields: ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk', fields: ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk',
@ -151,7 +152,7 @@ module.exports = Self => {
}); });
const [observation] = address.observations(); const [observation] = address.observations();
if (observation) { if (observation) {
await models.TicketObservation.upsert({ await models.TicketObservation.create({
ticketFk: id, ticketFk: id,
observationTypeFk: observation.observationTypeFk, observationTypeFk: observation.observationTypeFk,
description: observation.description description: observation.description

View File

@ -5,6 +5,7 @@ describe('ticket componentUpdate()', () => {
const ticketID = 11; const ticketID = 11;
const today = new Date(); const today = new Date();
const tomorrow = new Date(); const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1); tomorrow.setDate(tomorrow.getDate() + 1);
let deliveryComponentId; let deliveryComponentId;
@ -124,22 +125,24 @@ describe('ticket componentUpdate()', () => {
const observationTypeDelivery = await app.models.ObservationType.findOne({ const observationTypeDelivery = await app.models.ObservationType.findOne({
where: {code: 'delivery'} where: {code: 'delivery'}
}); });
const ticketObservation = await app.models.TicketObservation.findOne({ const originalTicketObservation = await app.models.TicketObservation.findOne({
where: { where: {
ticketFk: ticketID, ticketFk: ticketID,
observationTypeFk: observationTypeDelivery.id} observationTypeFk: observationTypeDelivery.id}
}); });
expect(originalTicketObservation).toBeDefined();
await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, newAddressID, await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, newAddressID,
zoneID, warehouseID, companyID, shipped, landed, isDeleted, option); zoneID, warehouseID, companyID, shipped, landed, isDeleted, option);
const newTicketObservation = await app.models.TicketObservation.findOne({ const removedTicketObservation = await app.models.TicketObservation.findOne({
where: { where: {
ticketFk: ticketID, ticketFk: ticketID,
observationTypeFk: observationTypeDelivery.id} observationTypeFk: observationTypeDelivery.id}
}); });
expect(newTicketObservation).toBeNull(); expect(removedTicketObservation).toBeNull();
// restores // restores
await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, addressID, await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, addressID,
@ -151,6 +154,6 @@ describe('ticket componentUpdate()', () => {
observationTypeFk: observationTypeDelivery.id} observationTypeFk: observationTypeDelivery.id}
}); });
expect(restoredTicketObservation.description).toEqual(ticketObservation.description); expect(restoredTicketObservation.description).toEqual(originalTicketObservation.description);
}); });
}); });