Merge pull request 'fixed collection tests pollution' (#446) from 2495-updateCollectionSale_test_pollution_fix into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #446
Reviewed-by: Bernat Exposito <bernat@verdnatura.es>
This commit is contained in:
Bernat Exposito 2020-11-09 14:06:59 +00:00
commit c3b5987a1e
6 changed files with 111 additions and 31 deletions

View File

@ -1,13 +1,62 @@
const app = require('vn-loopback/server/server');
// #2495 updateCollectionSale reparar polución de unitarios
xdescribe('updateCollectionSale()', () => {
it('return a new collection', async() => {
describe('updateCollectionSale()', () => {
it('should return a new collection', async() => {
const sectorOneWarehouseID = 1;
let ctx = {req: {accessToken: {userId: 106}}};
let response = await app.models.Collection.updateCollectionSale(ctx, 1, 5, 5, 5, 1, 4, false, 'UXN', 1, 1);
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);
expect(response.length).toBeGreaterThan(0);
expect(response[0][0].id).toEqual(1);
expect(response[0][0].quantity).toEqual(5);
// 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();
});
});

View File

@ -65,25 +65,26 @@ module.exports = Self => {
}
});
Self.updateCollectionSale = async(ctx, sale, originalQuantity, quantity, quantityPicked, ticketFk, stateFk, isNicho, shelvingFk, itemFk, sectorFk) => {
Self.updateCollectionSale = async ctx => {
const userId = ctx.req.accessToken.userId;
const args = ctx.args;
if (originalQuantity == quantity) {
if (args.originalQuantity == args.quantity) {
query = `CALL vn.collection_updateSale(?,?,?,?,?)`;
await Self.rawSql(query, [sale, originalQuantity, userId, stateFk, ticketFk]);
await Self.rawSql(query, [args.sale, args.originalQuantity, userId, args.stateFk, args.ticketFk]);
}
if (!isNicho) {
if (!args.isNicho) {
query = `CALL vn.collection_faults(?,?,?)`;
await Self.rawSql(query, [shelvingFk, quantityPicked, itemFk]);
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, args.itemFk]);
} else {
query = `CALL vn.sector_getWarehouse(?)`;
const [result] = await Self.rawSql(query, [sectorFk]);
const [result] = await Self.rawSql(query, [args.sectorFk]);
query = `CALL vn.itemPlacementSave(?,?,?)`;
await Self.rawSql(query, [shelvingFk, quantityPicked, result[0]['warehouseFk']]);
await Self.rawSql(query, [args.shelvingFk, args.quantityPicked, result[0]['warehouseFk']]);
}
query = `CALL vn.sale_updateOriginalQuantity(?,?)`;
return await Self.rawSql(query, [sale, quantity]);
return await Self.rawSql(query, [args.sale, args.quantity]);
};
};

View File

@ -7,8 +7,18 @@
}
},
"properties": {
"id": {
"type": "Number",
"id": true
},
"code": {
"type": "String"
},
"itemFk": {
"type": "Number"
},
"warehouseFk": {
"type": "Number"
}
},
"relations": {

View File

@ -8,18 +8,24 @@
},
"properties": {
"id": {
"type": "number",
"type": "Number",
"id": true,
"description": "Identifier"
},
"shelve": {
"type": "string"
"type": "String"
},
"shelvingFk": {
"type": "String"
},
"itemFk": {
"type": "Number"
},
"deep": {
"type": "number"
"type": "Number"
},
"quantity": {
"type": "number"
"type": "Number"
},
"created": {
"type": "Date"

View File

@ -12,6 +12,12 @@
"type": "Number",
"forceId": false
},
"saleFk": {
"type": "Number"
},
"stateFk": {
"type": "Number"
},
"isChecked": {
"type": "boolean"
},

View File

@ -5,22 +5,30 @@
"model": "TicketLog",
"relation": "ticket",
"showField": "stateFk"
},
"options": {
"mysql": {
"table": "ticketTracking"
}
},
},
"options": {
"mysql": {
"table": "ticketTracking"
}
},
"properties": {
"id": {
"id": true,
"type": "Number",
"forceId": false
},
"created": {
"type": "Date",
"required": false
}
"id": {
"id": true,
"type": "Number",
"forceId": false
},
"created": {
"type": "Date"
},
"ticketFk": {
"type": "Number"
},
"stateFk": {
"type": "Number"
},
"workerFk": {
"type": "Number"
}
},
"relations": {
"ticket": {