44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const app = require(`${servicesDir}/ticket/server/server`);
|
|
|
|
describe('ticket new()', () => {
|
|
let ticket;
|
|
let today = new Date();
|
|
let ctx = {req: {accessToken: {userId: 1}}};
|
|
|
|
afterAll(async () => {
|
|
await app.models.Ticket.destroyById(ticket.id);
|
|
});
|
|
|
|
it('should throw an error if the address doesnt exist', async () => {
|
|
let error;
|
|
let params = {addressFk: 'invalid address', clientFk: 104};
|
|
|
|
await app.models.Ticket.new(ctx, params)
|
|
.catch(response => {
|
|
expect(response.message).toEqual(`This address doesn't exist`);
|
|
error = response;
|
|
});
|
|
|
|
expect(error).toBeDefined();
|
|
});
|
|
|
|
it('should return the id of the created ticket', async () => {
|
|
let params = {
|
|
warehouseFk: 1,
|
|
clientFk: 104,
|
|
companyFk: 442,
|
|
addressFk: 4,
|
|
agencyModeFk: 1,
|
|
userId: 9,
|
|
shipped: today,
|
|
landed: today
|
|
};
|
|
|
|
ticket = await app.models.Ticket.new(ctx, params);
|
|
|
|
let newestTicketIdInFixtures = 21;
|
|
|
|
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures);
|
|
});
|
|
});
|