salix/back/methods/collection/spec/updateCollectionSale.spec.js

63 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-03-30 12:28:29 +00:00
const app = require('vn-loopback/server/server');
2020-11-09 13:53:26 +00:00
describe('updateCollectionSale()', () => {
it('should return a new collection', async() => {
const sectorOneWarehouseID = 1;
let ctx = {req: {accessToken: {userId: 1106}}};
2020-11-09 13:53:26 +00:00
ctx.args = {
sale: 1,
originalQuantity: 5,
quantity: 5,
quantityPicked: 5,
ticketFk: 1,
stateFk: 4,
isNicho: false,
shelvingFk: 'UXN',
itemFk: 1,
sectorFk: 1
};
let originalSaleTracking = await app.models.SaleTracking.findOne({
where: {
saleFk: ctx.args.sale,
stateFk: ctx.args.stateFk
}
});
let itemPlacement = await app.models.ItemPlacement.findOne({
where: {
itemFk: ctx.args.itemFk,
warehouseFk: sectorOneWarehouseID
}
});
const originalSale = await app.models.Sale.findById(ctx.args.sale);
const originalItemShelving = await app.models.ItemShelving.findOne({where: {shelvingFk: ctx.args.shelvingFk, itemFk: ctx.args.itemFk}});
const originalTicketLastState = await app.models.TicketLastState.findById(ctx.args.ticketFk);
let response = await app.models.Collection.updateCollectionSale(ctx);
2020-03-26 18:10:09 +00:00
2020-03-30 12:28:29 +00:00
expect(response.length).toBeGreaterThan(0);
expect(response[0][0].id).toEqual(1);
expect(response[0][0].quantity).toEqual(5);
2020-11-09 13:53:26 +00:00
// restores
if (originalSaleTracking)
await originalSaleTracking.save();
else {
originalSaleTracking = await app.models.SaleTracking.findOne({
where: {
saleFk: ctx.args.sale,
stateFk: ctx.args.stateFk
}
});
await originalSaleTracking.destroy();
}
await originalSale.save();
const itemShelvingsToDestroy = await app.models.ItemShelving.find({where: {shelvingFk: ctx.args.shelvingFk, itemFk: ctx.args.itemFk}});
for (itemShelving of itemShelvingsToDestroy)
await itemShelving.destroy();
await originalItemShelving.save();
await originalTicketLastState.save();
await itemPlacement.save();
2020-03-26 18:10:09 +00:00
});
});