2996-route_tickets_recalc #677

Merged
joan merged 3 commits from 2996-route_tickets_recalc into dev 2021-06-28 09:18:20 +00:00
4 changed files with 17 additions and 12 deletions

View File

@ -48,12 +48,12 @@ module.exports = Self => {
scope: { scope: {
fields: ['id', 'm3', 'numberPlate'] fields: ['id', 'm3', 'numberPlate']
} }
} },
], ]
}; };
summary.route = await Self.app.models.Route.findOne(filter); 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; return summary;
}; };

View File

@ -133,7 +133,7 @@ describe('Component vnRouteIndex', () => {
}); });
describe('insert()', () => { 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.$.model, 'refresh').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');

View File

@ -131,6 +131,7 @@ class Controller extends Section {
.then(() => { .then(() => {
this.$.model.data = this.$.model.data.concat(tickets); this.$.model.data = this.$.model.data.concat(tickets);
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
this.updateVolume();
}); });
} }
@ -157,8 +158,7 @@ class Controller extends Section {
const query = `Routes/${this.route.id}/insertTicket`; const query = `Routes/${this.route.id}/insertTicket`;
return this.$http.patch(query, {ticketId}).then(() => { return this.$http.patch(query, {ticketId}).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.model.refresh(); this.updateVolume();
this.card.reload();
}).catch(error => { }).catch(error => {
if (error.status == 404) if (error.status == 404)
return this.vnApp.showError(this.$t('Ticket not found')); return this.vnApp.showError(this.$t('Ticket not found'));

View File

@ -129,19 +129,20 @@ describe('Route', () => {
describe('removeTicketFromRoute()', () => { describe('removeTicketFromRoute()', () => {
it('should perform a patch query then call showSuccess and updateVolume methods', () => { 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.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove'); jest.spyOn(controller.$.model, 'remove');
let ticketId = 1; let ticketId = 1;
controller.selectedTicket = ticketId; controller.selectedTicket = ticketId;
$httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200);
$httpBackend.expectPATCH(`Tickets/${ticketId}/`).respond('ok'); $httpBackend.expectPATCH(`Tickets/${ticketId}/`).respond('ok');
controller.removeTicketFromRoute(); controller.removeTicketFromRoute();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket removed from route'); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket removed from route');
expect(controller.updateVolume).toHaveBeenCalledWith();
}); });
}); });
@ -196,9 +197,8 @@ describe('Route', () => {
describe('setTicketsRoute()', () => { describe('setTicketsRoute()', () => {
it('should perform a POST query to add tickets to the route', () => { it('should perform a POST query to add tickets to the route', () => {
controller.$.model = {data: [ controller.$params = {id: 1101};
{id: 1, checked: false} controller.$.model.data = [{id: 1, checked: false}];
]};
const existingTicket = controller.$.model.data[0]; const existingTicket = controller.$.model.data[0];
@ -217,7 +217,8 @@ describe('Route', () => {
{id: 5} {id: 5}
]; ];
$httpBackend.expectPOST(`Tickets/crud`).respond(); $httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200);
$httpBackend.expectPOST('Tickets/crud').respond();
controller.setTicketsRoute(); controller.setTicketsRoute();
$httpBackend.flush(); $httpBackend.flush();
@ -273,11 +274,15 @@ describe('Route', () => {
describe('insert()', () => { describe('insert()', () => {
it('should make a HTTP patch query and then call both refresh and showSuccess methods', () => { 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.$.model, 'refresh').mockReturnThis();
jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.vnApp, 'showSuccess');
const ticketId = 11; const ticketId = 11;
const data = {ticketId}; const data = {ticketId};
$httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200);
$httpBackend.expect('PATCH', `Routes/1/insertTicket`, data).respond(); $httpBackend.expect('PATCH', `Routes/1/insertTicket`, data).respond();
controller.insert(ticketId); controller.insert(ticketId);
$httpBackend.flush(); $httpBackend.flush();