Updated back unit test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-03-27 09:10:30 +01:00
parent 835c415ba7
commit d4ca58edad
4 changed files with 107 additions and 6 deletions

View File

@ -554,6 +554,10 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des
(10, 23, 4, 'Reclama ticket: 8'), (10, 23, 4, 'Reclama ticket: 8'),
(11, 24, 4, 'Reclama ticket: 7'); (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`) INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`)
VALUES VALUES
(1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)), (1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)),

View File

@ -3,40 +3,100 @@ const app = require('vn-loopback/server/server');
describe('ticket deleteStowaway()', () => { describe('ticket deleteStowaway()', () => {
const shipId = 16; const shipId = 16;
const stowawayId = 17; 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() => { it('should create an stowaway', async() => {
await app.models.Stowaway.rawSql(` await app.models.Stowaway.rawSql(`
INSERT INTO stowaway (id, shipFk) VALUES (?, ?) INSERT INTO stowaway (id, shipFk) VALUES (?, ?)
`, [stowawayId, shipId]); `, [stowawayId, shipId]);
await app.models.Stowaway.rawSql(
`CALL ticketStateUpdate(?, ?)`, [shipId, 'BOARDING']);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId}); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(1); 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() => { 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}); const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(0); 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() => { it('should create again an stowaway', async() => {
await app.models.Stowaway.rawSql(` await app.models.Stowaway.rawSql(`
INSERT INTO stowaway (id, shipFk) VALUES (?, ?) 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); expect(stowawayExists).toEqual(1);
}); });
it('should delete the stowaway from the stowaway ticket', async() => { it('should confirm that the stowaway ticket is on "BOARDING" state', async() => {
await app.models.Ticket.deleteStowaway(stowawayId); 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); 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');
});
}); });

View File

@ -56,6 +56,9 @@
"TicketState":{ "TicketState":{
"dataSource": "vn" "dataSource": "vn"
}, },
"TicketLastState":{
"dataSource": "vn"
},
"TicketService":{ "TicketService":{
"dataSource": "vn" "dataSource": "vn"
}, },

View File

@ -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"
}
}
}