refs #5513 addFromPackaging.spec.js
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-05-04 14:30:10 +02:00
parent 8ae5a0de0f
commit 5cdec35ed4
3 changed files with 59 additions and 6 deletions

View File

@ -2863,6 +2863,10 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`)
(2, 1, 50, 2),
(3, 1, 0, 3);
INSERT INTO `vn`.`travelConfig` (id, warehouseInFk, warehouseOutFk, agencyFk, companyFk)
VALUES
(1, 1, 1, 1, 442);
INSERT INTO `vn`.`buyConfig` (id, showLastBuy)
VALUES
(1, 6);

View File

@ -48,9 +48,9 @@ module.exports = Self => {
tomorrow.setDate(today.getDate() + 1);
const travel = await models.Travel.create({
shipmentHour: args.isTravelReception ? yesterday : today,
landingHour: args.isTravelReception ? today : tomorrow,
agencyFk: travelConfig.agencyFk,
shipped: args.isTravelReception ? yesterday : today,
landed: args.isTravelReception ? today : tomorrow,
agencyModeFk: travelConfig.agencyFk,
warehouseInFk: travelConfig.warehouseOutFk,
warehouseOutFk: travelConfig.warehouseInFk
}, myOptions);
@ -63,7 +63,7 @@ module.exports = Self => {
if (tx) await tx.commit();
return {travel, entry};
return entry;
} catch (e) {
if (tx) await tx.rollback();
throw e;

View File

@ -0,0 +1,49 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('entry addFromPackaging()', () => {
const supplier = 442;
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
beforeAll(async() => {
const activeCtx = {
accessToken: {userId: 49},
http: {
req: {
headers: {origin: 'http://localhost'},
},
},
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx,
});
});
it('should create a receipt travel', async() => {
const ctx = {args: {isTravelReception: true, supplier}};
const tx = await models.Entry.beginTransaction({});
const options = {transaction: tx};
try {
const entry = await models.Entry.addFromPackaging(ctx, options);
const travelConfig = await models.TravelConfig.findOne({}, options);
const travel = await models.Travel.findOne({order: 'id DESC'}, options);
expect(new Date(travel.shipped).getDate()).toEqual(yesterday.getDate());
expect(new Date(travel.landed).getDate()).toEqual(today.getDate());
expect(travel.agencyModeFk).toEqual(travelConfig.agencyFk);
expect(travel.warehouseInFk).toEqual(travelConfig.warehouseOutFk);
expect(travel.warehouseOutFk).toEqual(travelConfig.warehouseInFk);
expect(entry.supplierFk).toEqual(supplier);
expect(entry.travelFk).toEqual(travel.id);
expect(entry.companyFk).toEqual(travelConfig.companyFk);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});