From d4ca58edad0cba6c827415d5e32582ba70a9f0da Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 27 Mar 2020 09:10:30 +0100 Subject: [PATCH] Updated back unit test --- db/dump/fixtures.sql | 4 ++ .../ticket/specs/deleteStowaway.spec.js | 72 +++++++++++++++++-- modules/ticket/back/model-config.json | 3 + .../ticket/back/models/ticket-last-state.json | 34 +++++++++ 4 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 modules/ticket/back/models/ticket-last-state.json diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 331d115a3..4218e15d1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -554,6 +554,10 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des (10, 23, 4, 'Reclama ticket: 8'), (11, 24, 4, 'Reclama ticket: 7'); +-- FIX for state hours on local, inter_afterInsert +UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND); + + INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) VALUES (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), diff --git a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js index 3c8097e37..bd6fd327a 100644 --- a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js +++ b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js @@ -3,40 +3,100 @@ const app = require('vn-loopback/server/server'); describe('ticket deleteStowaway()', () => { const shipId = 16; const stowawayId = 17; + const ctx = { + req: { + accessToken: {userId: 18}, + headers: {origin: 'http://localhost'} + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + + afterAll(async() => { + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'OK']); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'OK']); + }); it('should create an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) `, [stowawayId, shipId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [shipId, 'BOARDING']); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(1); }); + it('should confirm that the ship ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('Embarcando'); + }); + it('should delete the stowaway from the ship ticket', async() => { - await app.models.Ticket.deleteStowaway(shipId); + await app.models.Ticket.deleteStowaway(ctx, shipId); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); expect(stowawayExists).toEqual(0); }); + it('should confirm that the ship ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: shipId + } + }); + + expect(shipState.name).toEqual('OK'); + }); + it('should create again an stowaway', async() => { await app.models.Stowaway.rawSql(` INSERT INTO stowaway (id, shipFk) VALUES (?, ?) - `, [stowawayId, shipId]); + `, [shipId, stowawayId]); + await app.models.Stowaway.rawSql( + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'BOARDING']); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(1); }); - it('should delete the stowaway from the stowaway ticket', async() => { - await app.models.Ticket.deleteStowaway(stowawayId); + it('should confirm that the stowaway ticket is on "BOARDING" state', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); - const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); + expect(shipState.name).toEqual('Embarcando'); + }); + + it('should delete the stowaway from the stowaway ticket', async() => { + await app.models.Ticket.deleteStowaway(ctx, stowawayId); + + const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId}); expect(stowawayExists).toEqual(0); }); + + it('should confirm that the stowaway ticket is not on "BOARDING" state anymore', async() => { + const shipState = await app.models.TicketLastState.findOne({ + where: { + ticketFk: stowawayId + } + }); + + expect(shipState.name).toEqual('OK'); + }); }); diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 10c10b134..ac6f4f100 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -56,6 +56,9 @@ "TicketState":{ "dataSource": "vn" }, + "TicketLastState":{ + "dataSource": "vn" + }, "TicketService":{ "dataSource": "vn" }, diff --git a/modules/ticket/back/models/ticket-last-state.json b/modules/ticket/back/models/ticket-last-state.json new file mode 100644 index 000000000..890d800af --- /dev/null +++ b/modules/ticket/back/models/ticket-last-state.json @@ -0,0 +1,34 @@ +{ + "name": "TicketLastState", + "base": "VnModel", + "options": { + "mysql": { + "table": "ticketLastState" + } + }, + "properties": { + "name": { + "type": "string" + }, + "ticketFk": { + "id": 1, + "type": "Number" + }, + "ticketTrackingFk": { + "id": 2, + "type": "Number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "ticketTracking": { + "type": "belongsTo", + "model": "TicketTracking", + "foreignKey": "ticketTrackingFk" + } + } +}