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

66 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-11-30 10:45:17 +00:00
const app = require(`${servicesDir}/order/server/server`);
describe('Order updateBasicData', () => {
afterAll(async () => {
let validparams = {note: null};
2018-11-30 10:55:56 +00:00
let orderId = 21;
2018-11-30 10:45:17 +00:00
await app.models.Order.updateBasicData(validparams, orderId);
});
it('should return an error if the order is confirmed', async () => {
let error;
let params = [];
let orderConfirmed = 1;
await app.models.Order.updateBasicData(params, orderConfirmed)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You can't make changes on the basic data of an confirmed order or with rows`);
});
it('should return an error if the order has rows', async () => {
let error;
let params = [];
let orderWithRows = 16;
await app.models.Order.updateBasicData(params, orderWithRows)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You can't make changes on the basic data of an confirmed order or with rows`);
});
it('should return an error if the user is administrative and the isTaxDataChecked value is true BUT the params aint valid', async () => {
let error;
let invalidparams = {invalid: 'param for update'};
2018-11-30 10:56:52 +00:00
let orderId = 21;
2018-11-30 10:45:17 +00:00
await app.models.Order.updateBasicData(invalidparams, orderId)
.catch(e => {
error = e;
});
expect(error.toString()).toContain(`You don't have enough privileges to do that`);
});
it('should update the client fiscal data and return the count if changes made', async () => {
let validparams = {note: 'test note'};
2018-11-30 10:55:56 +00:00
let orderId = 21;
2018-11-30 10:45:17 +00:00
let order = await app.models.Order.findById(orderId);
expect(order.note).toEqual(null);
let result = await app.models.Order.updateBasicData(validparams, orderId);
expect(result.note).toEqual('test note');
});
});