61 lines
1.7 KiB
JavaScript
61 lines
1.7 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
let UserError = require('vn-loopback/util/user-error');
|
|
|
|
describe('ticket getPossibleStowaways()', () => {
|
|
it(`should throw an error if Can't create stowaway for this ticket`, async() => {
|
|
const tx = await models.Ticket.beginTransaction({});
|
|
|
|
let error;
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ticketId = 10;
|
|
await models.Ticket.getPossibleStowaways(ticketId, options);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
error = e;
|
|
}
|
|
|
|
expect(error).toEqual(new UserError(`Can't create stowaway for this ticket`));
|
|
});
|
|
|
|
it('should return an empty list of tickets for a valid ticket', async() => {
|
|
const tx = await models.Ticket.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ticketId = 12;
|
|
const possibleStowaways = await models.Ticket.getPossibleStowaways(ticketId, options);
|
|
|
|
expect(possibleStowaways.length).toEqual(0);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
|
|
it('should return allowed list of tickets for a valid ticket', async() => {
|
|
const tx = await models.Ticket.beginTransaction({});
|
|
|
|
try {
|
|
const options = {transaction: tx};
|
|
|
|
const ticketId = 16;
|
|
const possibleStowaways = await models.Ticket.getPossibleStowaways(ticketId, options);
|
|
|
|
expect(possibleStowaways.length).toEqual(1);
|
|
|
|
await tx.rollback();
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
});
|
|
});
|