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: {
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;
};

View File

@ -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');

View File

@ -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'));

View File

@ -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();