salix/modules/ticket/back/methods/sale/specs/priceDifference.spec.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-01-24 08:08:28 +00:00
const app = require('vn-loopback/server/server');
let UserError = require('vn-loopback/util/user-error');
describe('sale priceDifference()', () => {
2018-08-17 06:41:30 +00:00
it('should return ticket price differences', async() => {
let data = {
2018-08-17 06:41:30 +00:00
landed: new Date(),
addressFk: 121,
agencyModeFk: 1,
warehouseFk: 1
};
let result = await app.models.Sale.priceDifference(11, data);
2018-08-17 06:41:30 +00:00
expect(result.totalUnitPrice).toEqual(4.5);
expect(result.totalNewPrice).toEqual(4.24);
expect(result.totalDifference).toEqual(3.75);
});
it('should return an error if the ticket state is not valid for modifications', async() => {
let error;
let data = {
landed: new Date(),
addressFk: 121,
agencyModeFk: 1,
warehouseFk: 1
};
await app.models.Sale.priceDifference(1, data)
.catch(e => {
error = e;
});
expect(error).toEqual(new UserError(`The sales of this ticket can't be modified`));
});
});