#1681 crear test para el endpoint getPossibleStowaways
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-09-13 07:40:27 +02:00
parent f0253fd1ce
commit c6507fc2bb
2 changed files with 31 additions and 1 deletions

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('getPossibleStowaways', { Self.remoteMethod('getPossibleStowaways', {
description: 'Returns mana of a salesperson of a ticket', description: 'Returns a list of allowed tickets for a stowaway ticket',
accessType: 'READ', accessType: 'READ',
accepts: [{ accepts: [{
arg: 'id', arg: 'id',

View File

@ -0,0 +1,30 @@
const app = require('vn-loopback/server/server');
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() => {
let error;
let ticketId = 10;
await app.models.Ticket.getPossibleStowaways(ticketId)
.catch(e => {
error = e;
});
expect(error).toEqual(new UserError(`Can't create stowaway for this ticket`));
});
// EL TICKET 12 DEVUELVE UNA LISTA VACIA
it('should return an empty list of tickets for a valid ticket', async() => {
let ticketId = 12;
let possibleStowaways = await app.models.Ticket.getPossibleStowaways(ticketId);
expect(possibleStowaways.length).toEqual(0);
});
it('should return allowed list of tickets for a valid ticket', async() => {
let ticketId = 16;
let possibleStowaways = await app.models.Ticket.getPossibleStowaways(ticketId);
expect(possibleStowaways.length).toEqual(1);
});
});