const app = require(`${servicesDir}/order/server/server`); let UserError = require('../../../helpers').UserError; describe('order new()', () => { let orderId; afterAll(async () => { await app.models.Order.destroyById(orderId); }); 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}; 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}; 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, landed: new Date() }; 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 }; orderId = await app.models.Order.new(params); let highestOrderIdInFixtures = 3; expect(orderId).toBeGreaterThan(highestOrderIdInFixtures); }); });