67 lines
2.0 KiB
JavaScript
67 lines
2.0 KiB
JavaScript
|
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: 25521};
|
||
|
|
||
|
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: 25522};
|
||
|
|
||
|
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 = 4;
|
||
|
|
||
|
expect(orderId).toBeGreaterThan(highestOrderIdInFixtures);
|
||
|
});
|
||
|
});
|