103 lines
3.2 KiB
JavaScript
103 lines
3.2 KiB
JavaScript
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(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 (?, ?)
|
|
`, [shipId, stowawayId]);
|
|
await app.models.Stowaway.rawSql(
|
|
`CALL ticketStateUpdate(?, ?)`, [stowawayId, 'BOARDING']);
|
|
|
|
const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId});
|
|
|
|
expect(stowawayExists).toEqual(1);
|
|
});
|
|
|
|
it('should confirm that the stowaway ticket is on "BOARDING" state', async() => {
|
|
const shipState = await app.models.TicketLastState.findOne({
|
|
where: {
|
|
ticketFk: stowawayId
|
|
}
|
|
});
|
|
|
|
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');
|
|
});
|
|
});
|