2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2019-04-01 13:04:09 +00:00
|
|
|
let UserError = require('vn-loopback/util/user-error');
|
2018-05-16 06:13:39 +00:00
|
|
|
|
|
|
|
describe('sale priceDifference()', () => {
|
2018-08-17 06:41:30 +00:00
|
|
|
it('should return ticket price differences', async() => {
|
2019-05-30 06:41:08 +00:00
|
|
|
let tomorrow = new Date();
|
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
2018-05-16 06:13:39 +00:00
|
|
|
let data = {
|
2019-05-30 06:41:08 +00:00
|
|
|
landed: tomorrow,
|
2019-06-21 11:19:51 +00:00
|
|
|
addressFk: 126,
|
2019-05-30 06:41:08 +00:00
|
|
|
agencyModeFk: 7,
|
2018-05-30 08:55:54 +00:00
|
|
|
warehouseFk: 1
|
2018-05-16 06:13:39 +00:00
|
|
|
};
|
2019-06-21 11:19:51 +00:00
|
|
|
let result = await app.models.Sale.priceDifference(16, data);
|
2018-08-17 06:41:30 +00:00
|
|
|
|
2019-06-27 07:03:03 +00:00
|
|
|
expect(result.totalUnitPrice).toEqual(215.77);
|
|
|
|
expect(result.totalNewPrice).toEqual(215.77);
|
2019-05-30 06:41:08 +00:00
|
|
|
expect(result.totalDifference).toEqual(0);
|
2019-04-01 13:04:09 +00:00
|
|
|
});
|
|
|
|
|
2019-06-19 12:40:47 +00:00
|
|
|
it('should return an error if the ticket is not editable', async() => {
|
2019-04-01 13:04:09 +00:00
|
|
|
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`));
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
});
|