salix/modules/item/back/methods/item/specs/updateTaxes.spec.js

50 lines
1.3 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('item updateTaxes()', () => {
beforeAll.mockLoopBackContext();
it('should throw an error if the taxClassFk is blank', async() => {
const tx = await models.Item.beginTransaction({});
const options = {transaction: tx};
let error;
try {
const taxes = [{id: 3, taxClassFk: undefined}];
await models.Item.updateTaxes(taxes, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toEqual('Tax class cannot be blank');
});
it('should update the tax of a given country of an item', async() => {
const tx = await models.Item.beginTransaction({});
const options = {transaction: tx};
try {
let taxCountry = await models.ItemTaxCountry.findById(3, null, options);
expect(taxCountry.taxClassFk).toEqual(1);
const taxes = [{id: 3, taxClassFk: 2}];
await models.Item.updateTaxes(taxes, options);
taxCountry = await models.ItemTaxCountry.findById(3, null, options);
expect(taxCountry.taxClassFk).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});