From 320c04b2d39c8ec1ac511862560ba6f50172c1f3 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 24 Jun 2021 09:54:07 +0200 Subject: [PATCH 1/2] update volume is not called when add/remove tickets from route --- modules/route/front/index/index.spec.js | 2 +- modules/route/front/tickets/index.js | 4 ++-- modules/route/front/tickets/index.spec.js | 17 +++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/route/front/index/index.spec.js b/modules/route/front/index/index.spec.js index 8143f1157..80e660b76 100644 --- a/modules/route/front/index/index.spec.js +++ b/modules/route/front/index/index.spec.js @@ -133,7 +133,7 @@ describe('Component vnRouteIndex', () => { }); describe('insert()', () => { - it('should make a HTTP patch query and then call both refresh and showSuccess methods', () => { + it('should perform a HTTP patch query and then call both refresh and showSuccess methods', () => { jest.spyOn(controller.$.model, 'refresh').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index ffae4bac5..efb3d1498 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -131,6 +131,7 @@ class Controller extends Section { .then(() => { this.$.model.data = this.$.model.data.concat(tickets); this.vnApp.showSuccess(this.$t('Data saved!')); + this.updateVolume(); }); } @@ -157,8 +158,7 @@ class Controller extends Section { const query = `Routes/${this.route.id}/insertTicket`; return this.$http.patch(query, {ticketId}).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); - this.$.model.refresh(); - this.card.reload(); + this.updateVolume(); }).catch(error => { if (error.status == 404) return this.vnApp.showError(this.$t('Ticket not found')); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index 1fcf92448..4fafc4750 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -129,19 +129,20 @@ describe('Route', () => { describe('removeTicketFromRoute()', () => { it('should perform a patch query then call showSuccess and updateVolume methods', () => { - jest.spyOn(controller, 'updateVolume').mockReturnThis(); + controller.$params = {id: 1101}; + jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); let ticketId = 1; controller.selectedTicket = ticketId; + $httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200); $httpBackend.expectPATCH(`Tickets/${ticketId}/`).respond('ok'); controller.removeTicketFromRoute(); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket removed from route'); - expect(controller.updateVolume).toHaveBeenCalledWith(); }); }); @@ -196,9 +197,8 @@ describe('Route', () => { describe('setTicketsRoute()', () => { it('should perform a POST query to add tickets to the route', () => { - controller.$.model = {data: [ - {id: 1, checked: false} - ]}; + controller.$params = {id: 1101}; + controller.$.model.data = [{id: 1, checked: false}]; const existingTicket = controller.$.model.data[0]; @@ -217,7 +217,8 @@ describe('Route', () => { {id: 5} ]; - $httpBackend.expectPOST(`Tickets/crud`).respond(); + $httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200); + $httpBackend.expectPOST('Tickets/crud').respond(); controller.setTicketsRoute(); $httpBackend.flush(); @@ -273,11 +274,15 @@ describe('Route', () => { describe('insert()', () => { it('should make a HTTP patch query and then call both refresh and showSuccess methods', () => { + controller.$params = {id: 1101}; + jest.spyOn(controller.$.model, 'refresh').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); const ticketId = 11; const data = {ticketId}; + + $httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200); $httpBackend.expect('PATCH', `Routes/1/insertTicket`, data).respond(); controller.insert(ticketId); $httpBackend.flush(); -- 2.40.1 From 3bfc08b117014f76e5e2d2341e6698a3ac10fa22 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 24 Jun 2021 10:06:31 +0200 Subject: [PATCH 2/2] route.summary order by priority --- modules/route/back/methods/route/summary.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/route/back/methods/route/summary.js b/modules/route/back/methods/route/summary.js index ad65edb4a..10cfe38ee 100644 --- a/modules/route/back/methods/route/summary.js +++ b/modules/route/back/methods/route/summary.js @@ -48,12 +48,12 @@ module.exports = Self => { scope: { fields: ['id', 'm3', 'numberPlate'] } - } - ], + }, + ] }; summary.route = await Self.app.models.Route.findOne(filter); - summary.tickets = await Self.app.models.Route.getTickets({id: id}); + summary.tickets = await Self.app.models.Route.getTickets({id: id, order: 'priority ASC'}); return summary; }; -- 2.40.1