salix/modules/order/back/methods/order/specs/getTaxes.spec.js

76 lines
2.1 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
describe('order getTaxes()', () => {
it('should call the getTaxes method and return undefined if its called with a string', async() => {
const tx = await models.Order.beginTransaction({});
try {
const options = {transaction: tx};
const result = await models.Order.getTaxes('string', options);
expect(result.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should call the getTaxes method and return undefined if its called with unknown id', async() => {
const tx = await models.Order.beginTransaction({});
try {
const options = {transaction: tx};
const result = await models.Order.getTaxes(9999, options);
expect(result.length).toEqual(0);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should call the getTaxes method and return the taxes splited if different type of taxes', async() => {
const tx = await models.Order.beginTransaction({});
try {
const options = {transaction: tx};
const result = await models.Order.getTaxes(1, options);
const expectedResult = result[0].tax + result[1].tax;
expect(expectedResult).toEqual(20.29);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should call the getTaxes method and return the taxes for them same type', async() => {
const tx = await models.Order.beginTransaction({});
try {
const options = {transaction: tx};
const result = await models.Order.getTaxes(2, options);
expect(result[0].tax).toEqual(9.1);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});