diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js new file mode 100644 index 000000000..9d08dce7a --- /dev/null +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -0,0 +1,41 @@ +const app = require('vn-loopback/server/server'); + +describe('route guessPriority()', () => { + const targetRouteId = 2; + let routeTicketsToRestore; + + afterAll(async done => { + let restoreFixtures = []; + routeTicketsToRestore.forEach(ticket => { + restoreFixtures.push(ticket.updateAttribute('priority', null)); + }); + await Promise.all(restoreFixtures); + + done(); + }); + + it('should confirm the tickets in the target route have no priority yet', async() => { + routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}}); + + expect(routeTicketsToRestore.length).toEqual(3); + expect(routeTicketsToRestore[0].priority).toBeNull(); + expect(routeTicketsToRestore[0].id).toEqual(7); + expect(routeTicketsToRestore[1].priority).toBeNull(); + expect(routeTicketsToRestore[1].id).toEqual(8); + expect(routeTicketsToRestore[2].priority).toBeNull(); + expect(routeTicketsToRestore[2].id).toEqual(9); + }); + + it('should call guessPriority() and then check the tickets in the target route now have their priorities defined', async() => { + await app.models.Route.guessPriority(targetRouteId); + let routeTickets = await app.models.Ticket.find({where: {routeFk: targetRouteId}, fields: ['id', 'priority']}); + + expect(routeTickets.length).toEqual(3); + expect(routeTickets[0].priority).toEqual(1); + expect(routeTickets[0].id).toEqual(7); + expect(routeTickets[1].priority).toEqual(3); + expect(routeTickets[1].id).toEqual(8); + expect(routeTickets[2].priority).toEqual(2); + expect(routeTickets[2].id).toEqual(9); + }); +});