salix/services/order/common/methods/order/specs/new.spec.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-08-17 14:12:05 +00:00
const app = require(`${servicesDir}/order/server/server`);
const UserError = require('vn-loopback/common/helpers').UserError;
describe('order new()', () => {
it('should throw an error if the client is frozen', async() => {
let error;
let params = {addressFk: 121};
await app.models.Order.new(params)
.catch(e => {
error = e;
});
expect(error).toEqual(new UserError(`You can't create an order for a frozen client`));
});
it('should throw an error if the client isnt frozen and isnt active', async() => {
let error;
let params = {addressFk: 6};
2018-08-17 14:12:05 +00:00
await app.models.Order.new(params)
.catch(e => {
error = e;
});
expect(error).toEqual(new UserError(`You can't create an order for a inactive client`));
});
it('should throw an error if the client isnt frozen and is active but doesnt have data checked', async() => {
let error;
let params = {addressFk: 7};
2018-08-17 14:12:05 +00:00
await app.models.Order.new(params)
.catch(e => {
error = e;
});
expect(error).toEqual(new UserError(`You can't create an order for a client that doesn't has tax data verified`));
});
it('should throw an error if the client isnt frozen and is active, has data checked but has a debt', async() => {
let error;
let params = {addressFk: 123};
await app.models.Order.new(params)
.catch(e => {
error = e;
});
expect(error).toEqual(new UserError(`You can't create an order for a client that has a debt`));
});
it('should create a new order for the user with id 105 when all conditions are met', async() => {
let params = {
landed: new Date(),
agencyModeFk: 1,
addressFk: 125
};
let orderId = await app.models.Order.new(params);
let highestOrderIdInFixtures = 3;
2018-08-17 14:12:05 +00:00
expect(orderId).toBeGreaterThan(highestOrderIdInFixtures);
});
});