8524-devToTest #3415
|
@ -1,25 +1,41 @@
|
||||||
const transfer = require('../transfer');
|
// const transfer = require('../transfer');
|
||||||
|
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Transfer merchandise from one entry to the next day()', () => {
|
describe('Transfer merchandise from one entry to the next day()', () => {
|
||||||
const ctx = {req: {accessToken: {userId: 18}}};
|
fit('should Transfer buys not located', async() => {
|
||||||
|
|
||||||
it('should Transfer buys not located', async() => {
|
|
||||||
const id = 3;
|
|
||||||
const item = 8;
|
|
||||||
const buy = 6;
|
|
||||||
const originalEntry = 4;
|
|
||||||
|
|
||||||
const tx = await models.ItemShelving.beginTransaction({});
|
const tx = await models.ItemShelving.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const id = 3;
|
||||||
|
const item = 8;
|
||||||
|
const buy = 6;
|
||||||
|
const originalEntry = 4;
|
||||||
|
const ctx = {req: {accessToken: {userId: 48}}};
|
||||||
|
|
||||||
const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options);
|
const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options);
|
||||||
await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options);
|
await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options);
|
||||||
const result = await models.Entry.transfer(ctx, originalEntry, options);
|
|
||||||
const buys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options);
|
|
||||||
|
|
||||||
expect(buys.length).toEqual(3);
|
const result = await models.Entry.transfer(ctx, originalEntry, options);
|
||||||
|
|
||||||
|
const originalEntrybuys = await models.Buy.find({where: {entryFk: originalEntry}}, options);
|
||||||
|
|
||||||
|
const newEntrybuys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options);
|
||||||
|
|
||||||
|
const itemShelvingsWithBuys = await models.Buy.find({
|
||||||
|
include: {
|
||||||
|
relation: 'itemShelving',
|
||||||
|
scope: {
|
||||||
|
fields: ['id'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where: {entryFk: originalEntry},
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
const hasItemShelving = await itemShelvingsWithBuys.filter(buy => buy.itemShelving().length);
|
||||||
|
|
||||||
|
expect(newEntrybuys.length).toEqual(originalEntrybuys.length - hasItemShelving.length);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -114,6 +114,11 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Delivery",
|
"model": "Delivery",
|
||||||
"foreignKey": "deliveryFk"
|
"foreignKey": "deliveryFk"
|
||||||
}
|
},
|
||||||
|
"itemShelving": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "ItemShelving",
|
||||||
|
"foreignKey": "buyFk"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,11 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Shelving",
|
"model": "Shelving",
|
||||||
"foreignKey": "shelvingFk"
|
"foreignKey": "shelvingFk"
|
||||||
}
|
},
|
||||||
|
"buy": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Buy",
|
||||||
|
"foreignKey": "buyFk"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue