#529 item/updateTaxes.js Backend unit tests
This commit is contained in:
parent
f03cdba029
commit
be85c784ed
|
@ -0,0 +1,40 @@
|
||||||
|
const app = require(`${servicesDir}/item/server/server`);
|
||||||
|
|
||||||
|
describe('item updateTaxes()', () => {
|
||||||
|
afterAll(async() => {
|
||||||
|
let taxesInFixtures = [{id: 509368, taxClassFk: 1}];
|
||||||
|
|
||||||
|
await app.models.Item.updateTaxes(taxesInFixtures);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if the taxClassFk is blank', async() => {
|
||||||
|
let error;
|
||||||
|
let taxes = [{id: 509368, taxClassFk: undefined}];
|
||||||
|
|
||||||
|
await app.models.Item.updateTaxes(taxes)
|
||||||
|
.catch(err => {
|
||||||
|
expect(err.message).toEqual('Tax class cannot be blank');
|
||||||
|
error = err;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update the tax of a given country of an item', async() => {
|
||||||
|
let taxCountry = await app.models.ItemTaxCountry.findById(509368);
|
||||||
|
|
||||||
|
expect(taxCountry.taxClassFk).toEqual(1);
|
||||||
|
|
||||||
|
let taxes = [{id: 509368, taxClassFk: 2}];
|
||||||
|
|
||||||
|
let result = await app.models.Item.updateTaxes(taxes);
|
||||||
|
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should confirm the tax class was updated', async() => {
|
||||||
|
let taxCountry = await app.models.ItemTaxCountry.findById(509368);
|
||||||
|
|
||||||
|
expect(taxCountry.taxClassFk).toEqual(2);
|
||||||
|
});
|
||||||
|
});
|
|
@ -11,7 +11,7 @@ module.exports = Self => {
|
||||||
description: 'The item id',
|
description: 'The item id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
}, {
|
}, {
|
||||||
arg: 'niches',
|
arg: 'taxes',
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The list of taxes to update',
|
description: 'The list of taxes to update',
|
||||||
|
@ -27,7 +27,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.updateTaxes = async(id, taxes) => {
|
Self.updateTaxes = async taxes => {
|
||||||
let promises = [];
|
let promises = [];
|
||||||
for (let tax of taxes) {
|
for (let tax of taxes) {
|
||||||
if (!tax.taxClassFk)
|
if (!tax.taxClassFk)
|
||||||
|
|
Loading…
Reference in New Issue