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

73 lines
2.2 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('item getBalance()', () => {
const ctx = beforeAll.getCtx();
it('should return the balance lines of a client type loses in which one has highlighted true', async() => {
const tx = await models.Item.beginTransaction({});
const options = {transaction: tx};
try {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx
});
const losesClientId = 1111;
const ticket = await models.Ticket.findById(7, null, options);
await ticket.updateAttribute('clientFk', losesClientId, options);
const filter = {
where: {
itemFk: 1,
warehouseFk: 1,
date: null
}
};
const results = await models.Item.getBalance(ctx, filter, options);
const result = results.find(element => element.clientType == 'loses');
expect(result.highlighted).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should show the claimFk only on the claimed item', async() => {
const tx = await models.Item.beginTransaction({});
const options = {transaction: tx};
try {
const firstFilter = {
where: {
itemFk: 1,
warehouseFk: 1,
date: null
}
};
const secondFilter = {
where: {
itemFk: 2,
warehouseFk: 1,
date: null
}
};
const firstItemBalance = await models.Item.getBalance(ctx, firstFilter, options);
const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options);
expect(firstItemBalance[9].claimFk).toEqual(null);
expect(secondItemBalance[7].claimFk).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});