tickets already in route are no longer shown + tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
0023a88bfc
commit
84378fd607
|
@ -20,6 +20,12 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.getSuggestedTickets = async id => {
|
||||
const ticketsInRoute = await Self.app.models.Ticket.find({
|
||||
where: {routeFk: id},
|
||||
fields: ['id']
|
||||
});
|
||||
const idsToExclude = ticketsInRoute.map(ticket => ticket.id);
|
||||
|
||||
const route = await Self.app.models.Route.findById(id);
|
||||
|
||||
const zoneAgencyModes = await Self.app.models.ZoneAgencyMode.find({
|
||||
|
@ -32,11 +38,26 @@ module.exports = Self => {
|
|||
for (let zoneAgencyMode of zoneAgencyModes)
|
||||
zoneIds.push(zoneAgencyMode.zoneFk);
|
||||
|
||||
const tickets = await Self.app.models.Ticket.find({
|
||||
let tickets = await Self.app.models.Ticket.find({
|
||||
where: {
|
||||
ageconyModeFk: route.agencyModeFk,
|
||||
zoneFk: {inq: zoneIds}
|
||||
}
|
||||
agencyModeFk: route.agencyModeFk,
|
||||
zoneFk: {inq: zoneIds},
|
||||
id: {nin: idsToExclude}
|
||||
},
|
||||
include: [
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['id', 'name']
|
||||
}
|
||||
},
|
||||
{
|
||||
relation: 'address',
|
||||
scope: {
|
||||
fields: ['id', 'street', 'postalCode', 'city'],
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
return tickets;
|
||||
|
|
|
@ -1,14 +1,30 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('route getSuggestedTickets()', () => {
|
||||
it('should return an array of suggested tickets', async() => {
|
||||
const result = await app.models.Route.getSuggestedTickets(1);
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 19},
|
||||
headers: {origin: 'http://localhost'}
|
||||
};
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
const routeID = 1;
|
||||
const ticketInRoute = await app.models.Ticket.findOne({where: {routeFk: routeID}});
|
||||
|
||||
await ticketInRoute.updateAttribute('routeFk', null);
|
||||
|
||||
const result = await app.models.Route.getSuggestedTickets(routeID);
|
||||
|
||||
const length = result.length;
|
||||
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
||||
|
||||
expect(result.length).toEqual(4);
|
||||
expect(result.length).toEqual(1);
|
||||
expect(anyResult.zoneFk).toEqual(1);
|
||||
expect(anyResult.agencyModeFk).toEqual(1);
|
||||
|
||||
await ticketInRoute.updateAttribute('routeFk', routeID);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -106,14 +106,26 @@ class Controller extends Section {
|
|||
setTicketsRoute() {
|
||||
let tickets = this.getSelectedItems(this.possibleTickets);
|
||||
if (tickets.length === 0) return;
|
||||
for (let i = 0; i < tickets.length; i++) {
|
||||
delete tickets[i].checked;
|
||||
tickets[i].routeFk = this.route.id;
|
||||
|
||||
const updates = [];
|
||||
|
||||
for (let ticket of tickets) {
|
||||
delete ticket.checked;
|
||||
const update = {
|
||||
where: {id: ticket.id},
|
||||
data: {routeFk: this.route.id}
|
||||
};
|
||||
|
||||
updates.push(update);
|
||||
}
|
||||
|
||||
return this.$.possibleTicketsModel.save().then(() => {
|
||||
this.$.model.data = this.$.model.data.concat(tickets);
|
||||
});
|
||||
const data = {creates: [], updates: updates, deletes: []};
|
||||
|
||||
return this.$http.post(`Tickets/crud`, data)
|
||||
.then(() => {
|
||||
this.$.model.data = this.$.model.data.concat(tickets);
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
});
|
||||
}
|
||||
|
||||
onDrop($event) {
|
||||
|
|
|
@ -37,42 +37,6 @@ describe('Route', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('buildPossibleTicketsFilter()', () => {
|
||||
it('should build the possible tickets filter', () => {
|
||||
let expectedFilter = {
|
||||
include: [
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}, {
|
||||
relation: 'address'
|
||||
}
|
||||
],
|
||||
where: {
|
||||
landed: {
|
||||
between: [
|
||||
jasmine.any(Date),
|
||||
jasmine.any(Date)
|
||||
]
|
||||
},
|
||||
routeFk: null,
|
||||
zoneFk: 67
|
||||
}
|
||||
};
|
||||
controller.route = {
|
||||
finished: new Date(),
|
||||
routeFk: null,
|
||||
zoneFk: 67
|
||||
};
|
||||
|
||||
controller.buildPossibleTicketsFilter();
|
||||
|
||||
expect(controller.possibleTicketsFilter).toEqual(expectedFilter);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHighestPriority()', () => {
|
||||
it('should return the highest value found in priorities plus 1', () => {
|
||||
controller.$.model = {data: [
|
||||
|
@ -228,13 +192,13 @@ describe('Route', () => {
|
|||
});
|
||||
|
||||
describe('setTicketsRoute()', () => {
|
||||
it('should perform a POST query to add tickets to the route', done => {
|
||||
controller.$.possibleTicketsModel = {save: () => {}};
|
||||
jest.spyOn(controller.$.possibleTicketsModel, 'save').mockReturnValue(Promise.resolve());
|
||||
it('should perform a POST query to add tickets to the route', () => {
|
||||
controller.$.model = {data: [
|
||||
{id: 1, checked: false}
|
||||
]};
|
||||
|
||||
const existingTicket = controller.$.model.data[0];
|
||||
|
||||
controller.route = {id: 111};
|
||||
|
||||
controller.possibleTickets = [
|
||||
|
@ -245,15 +209,16 @@ describe('Route', () => {
|
|||
];
|
||||
|
||||
let expectedResult = [
|
||||
{checked: false, id: 1},
|
||||
{id: 3, routeFk: 111},
|
||||
{id: 5, routeFk: 111}
|
||||
existingTicket,
|
||||
{id: 3},
|
||||
{id: 5}
|
||||
];
|
||||
|
||||
controller.setTicketsRoute().then(() => {
|
||||
expect(controller.$.model.data).toEqual(expectedResult);
|
||||
done();
|
||||
}).catch(done.fail);
|
||||
$httpBackend.expectPOST(`Tickets/crud`).respond();
|
||||
controller.setTicketsRoute();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$.model.data).toEqual(expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue