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

76 lines
2.2 KiB
JavaScript
Raw Normal View History

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