2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2023-04-12 10:33:14 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
2018-08-07 13:04:06 +00:00
|
|
|
|
|
|
|
describe('ticket model TicketTracking', () => {
|
2023-04-12 10:33:14 +00:00
|
|
|
beforeAll(async() => {
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
http: {
|
|
|
|
req: {
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
|
|
|
});
|
2018-08-07 13:04:06 +00:00
|
|
|
let ticketTrackingId;
|
|
|
|
|
2021-10-15 12:45:41 +00:00
|
|
|
afterAll(async() => {
|
2018-08-07 13:04:06 +00:00
|
|
|
await app.models.TicketPackaging.destroyById(ticketTrackingId);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should save a ticketTraing as the quantity is greater than 0', async() => {
|
|
|
|
let result = await app.models.TicketPackaging.create({ticketFk: 1, quantity: 1, packagingFk: 1});
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
ticketTrackingId = result.id;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error as the quantity is 0', async() => {
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
await app.models.TicketPackaging.create({ticketFk: 1, quantity: 0, packagingFk: 1});
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.message).toContain('Enter an integer different to zero');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error as the quantity isnt a number', async() => {
|
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
await app.models.TicketPackaging.create({ticketFk: 1, quantity: 'random string', packagingFk: 1});
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error.message).toContain('Enter an integer different to zero');
|
|
|
|
});
|
|
|
|
});
|