salix/services/loopback/common/methods/ticket/specs/new.spec.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket new()', () => {
2018-10-10 07:59:42 +00:00
let ticket;
2018-10-03 08:50:09 +00:00
let today = new Date();
2018-11-27 12:28:15 +00:00
let ctx = {req: {accessToken: {userId: 1}}};
2018-10-03 08:50:09 +00:00
2018-11-27 12:28:15 +00:00
afterAll(async () => {
2018-10-10 07:59:42 +00:00
await app.models.Ticket.destroyById(ticket.id);
2018-10-03 08:50:09 +00:00
});
2018-11-27 12:28:15 +00:00
it('should throw an error if the address doesnt exist', async () => {
let error;
2018-11-27 12:28:15 +00:00
let params = {addressFk: 'invalid address', clientFk: 104};
2018-11-27 12:28:15 +00:00
await app.models.Ticket.new(ctx, params)
.catch(response => {
expect(response.message).toEqual(`This address doesn't exist`);
error = response;
});
expect(error).toBeDefined();
});
2018-11-27 12:28:15 +00:00
it('should return the id of the created ticket', async () => {
let params = {
warehouseFk: 1,
2018-11-27 12:28:15 +00:00
clientFk: 104,
companyFk: 442,
2018-11-27 12:28:15 +00:00
addressFk: 4,
agencyModeFk: 1,
2018-10-03 08:50:09 +00:00
userId: 9,
shipped: today,
landed: today
};
2018-11-27 12:28:15 +00:00
ticket = await app.models.Ticket.new(ctx, params);
let newestTicketIdInFixtures = 21;
2018-10-10 07:59:42 +00:00
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures);
});
});