update fixtures, #1388 ticket descript change shiiped hour
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-05-03 12:23:57 +02:00
parent 0dbed4e102
commit 91e8b1f81b
8 changed files with 89 additions and 18 deletions

View File

@ -7,10 +7,6 @@ ALTER TABLE `vn2008`.`Colas`
CHANGE COLUMN `Id_Impresora` `Id_Impresora` TINYINT(3) UNSIGNED NULL DEFAULT NULL , CHANGE COLUMN `Id_Impresora` `Id_Impresora` TINYINT(3) UNSIGNED NULL DEFAULT NULL ,
CHANGE COLUMN `Id_Prioridad` `Id_Prioridad` TINYINT(3) UNSIGNED NULL DEFAULT NULL ; CHANGE COLUMN `Id_Prioridad` `Id_Prioridad` TINYINT(3) UNSIGNED NULL DEFAULT NULL ;
ALTER TABLE `vn2008`.`Colas` ALTER TABLE `vn2008`.`Colas`
ADD CONSTRAINT `Colas_ibfk_4`
FOREIGN KEY (`Id_Impresora`)
REFERENCES `vn2008`.`Impresoras` (`Id_Impresora`)
ON UPDATE CASCADE,
ADD CONSTRAINT `Colas_ibfk_3` ADD CONSTRAINT `Colas_ibfk_3`
FOREIGN KEY (`Id_Prioridad`) FOREIGN KEY (`Id_Prioridad`)
REFERENCES `vn2008`.`Prioridades` (`Id_Prioridad`) REFERENCES `vn2008`.`Prioridades` (`Id_Prioridad`)

View File

@ -3,10 +3,6 @@
ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1;
ALTER TABLE `vn2008`.`Consignatarios` AUTO_INCREMENT = 1; ALTER TABLE `vn2008`.`Consignatarios` AUTO_INCREMENT = 1;
INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`)
VALUES
('1', '6');
INSERT INTO `account`.`mailConfig` (`id`, `domain`) INSERT INTO `account`.`mailConfig` (`id`, `domain`)
VALUES VALUES
('1', 'verdnatura.es'); ('1', 'verdnatura.es');

View File

@ -81,5 +81,6 @@
"This ticket can't be invoiced": "Este ticket no puede ser facturado", "This ticket can't be invoiced": "Este ticket no puede ser facturado",
"That item is not available on that day": "El item no esta disponible para esa fecha", "That item is not available on that day": "El item no esta disponible para esa fecha",
"That item doesn't exists": "That item doesn't exists", "That item doesn't exists": "That item doesn't exists",
"You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado" "You cannot add or modify services to an invoiced ticket": "No puedes añadir o modificar servicios a un ticket facturado",
"This ticket can not be modified": "Este ticket no puede ser modificado"
} }

View File

@ -0,0 +1,34 @@
const app = require('vn-loopback/server/server');
describe('ticket updateEditableTicket()', () => {
const validTicketId = 12;
const invalidTicketId = 1;
const data = {addressFk: 1};
const originalData = {addressFk: 121};
afterAll(async done => {
await app.models.Ticket.updateEditableTicket(validTicketId, originalData);
done();
});
it('should throw an error if the ticket is not editable', async() => {
let error;
await app.models.Ticket.updateEditableTicket(invalidTicketId, data).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual('This ticket can not be modified');
});
expect(error).toBeDefined();
});
it('should edit the ticket address', async() => {
await app.models.Ticket.updateEditableTicket(validTicketId, data);
let updatedTicket = await app.models.Ticket.findById(validTicketId);
expect(updatedTicket.addressFk).toEqual(1);
});
});

View File

@ -0,0 +1,41 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('updateEditableTicket', {
description: 'Change data of a ticket',
accessType: 'WRITE',
accepts: [
{
arg: 'id',
type: 'number',
required: true,
description: 'Ticket id',
http: {source: 'path'}
},
{
arg: 'data',
description: 'Model instance data',
type: 'Object',
required: true,
http: {source: 'body'}
}
],
returns: {
type: 'object',
root: true
},
http: {
path: '/:id/updateEditableTicket',
verb: 'POST'
}
});
Self.updateEditableTicket = async(id, data) => {
let ticketIsEditable = await Self.app.models.Ticket.isEditable(id);
if (!ticketIsEditable)
throw new UserError('This ticket can not be modified');
let ticket = await Self.app.models.Ticket.findById(id);
await ticket.updateAttributes(data);
};
};

View File

@ -20,4 +20,5 @@ module.exports = Self => {
require('../methods/ticket/getPossibleStowaways')(Self); require('../methods/ticket/getPossibleStowaways')(Self);
require('../methods/ticket/canBeInvoiced')(Self); require('../methods/ticket/canBeInvoiced')(Self);
require('../methods/ticket/makeInvoice')(Self); require('../methods/ticket/makeInvoice')(Self);
require('../methods/ticket/updateEditableTicket')(Self);
}; };

View File

@ -51,8 +51,9 @@ class Controller {
changeShipped(response) { changeShipped(response) {
if (response === 'ACCEPT') { if (response === 'ACCEPT') {
let params = {shipped: this.newShipped}; let data = {shipped: this.newShipped};
this.$http.patch(`/ticket/api/Tickets/${this.ticket.id}`, params).then(() => { let query = `/ticket/api/Tickets/${this.ticket.id}/updateEditableTicket`;
this.$http.post(query, data).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Shipped hour updated')); this.vnApp.showSuccess(this.$translate.instant('Shipped hour updated'));
this.cardReload(); this.cardReload();
}); });

View File

@ -86,8 +86,8 @@ describe('Ticket Component vnTicketDescriptor', () => {
spyOn(controller.$state, 'reload'); spyOn(controller.$state, 'reload');
spyOn(controller.vnApp, 'showSuccess'); spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', `/ticket/api/Tickets/2/makeInvoice`).respond(); $httpBackend.when('POST', '/ticket/api/Tickets/2/makeInvoice').respond();
$httpBackend.expect('POST', `/ticket/api/Tickets/2/makeInvoice`).respond(); $httpBackend.expect('POST', '/ticket/api/Tickets/2/makeInvoice').respond();
controller.makeInvoice('ACCEPT'); controller.makeInvoice('ACCEPT');
$httpBackend.flush(); $httpBackend.flush();
@ -100,8 +100,8 @@ describe('Ticket Component vnTicketDescriptor', () => {
it('should make a query and show a success snackbar if the response is ACCEPT', () => { it('should make a query and show a success snackbar if the response is ACCEPT', () => {
spyOn(controller.vnApp, 'showSuccess'); spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('POST', `/invoiceOut/api/InvoiceOuts/1/regenerate`).respond(); $httpBackend.when('POST', '/invoiceOut/api/InvoiceOuts/1/regenerate').respond();
$httpBackend.expect('POST', `/invoiceOut/api/InvoiceOuts/1/regenerate`).respond(); $httpBackend.expect('POST', '/invoiceOut/api/InvoiceOuts/1/regenerate').respond();
controller.regenerateInvoice('ACCEPT'); controller.regenerateInvoice('ACCEPT');
$httpBackend.flush(); $httpBackend.flush();
@ -111,10 +111,12 @@ describe('Ticket Component vnTicketDescriptor', () => {
describe('changeShipped(response)', () => { describe('changeShipped(response)', () => {
it('should make a query and change the shipped hour if the response is ACCEPT', () => { it('should make a query and change the shipped hour if the response is ACCEPT', () => {
controller.ticket.id = 12;
spyOn(controller.vnApp, 'showSuccess'); spyOn(controller.vnApp, 'showSuccess');
spyOn(controller, 'cardReload'); spyOn(controller, 'cardReload');
$httpBackend.when('PATCH', `/ticket/api/Tickets/2`,).respond();
$httpBackend.expect('PATCH', `/ticket/api/Tickets/2`).respond(); $httpBackend.when('POST', '/ticket/api/Tickets/12/updateEditableTicket').respond();
$httpBackend.expect('POST', '/ticket/api/Tickets/12/updateEditableTicket').respond();
controller.changeShipped('ACCEPT'); controller.changeShipped('ACCEPT');
$httpBackend.flush(); $httpBackend.flush();
@ -123,4 +125,3 @@ describe('Ticket Component vnTicketDescriptor', () => {
}); });
}); });
}); });