#2687 - Travel CloneWithEntries #1887
|
@ -46,32 +46,72 @@ describe('Travel cloneWithEntries()', () => {
|
||||||
// });
|
// });
|
||||||
|
|
||||||
it(`should clone the travel and the containing entries`, async() => {
|
it(`should clone the travel and the containing entries`, async() => {
|
||||||
pending('#2687 - Cannot make a data rollback because of the triggers');
|
const tx = await models.Travel.beginTransaction({});
|
||||||
const warehouseThree = 3;
|
const warehouseThree = 3;
|
||||||
const agencyModeOne = 1;
|
const agencyModeOne = 1;
|
||||||
const yesterday = Date.vnNew();
|
try {
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
// pending('#2687 - Cannot make a data rollback because of the triggers');
|
||||||
|
|
||||||
travelBefore = await models.Travel.findById(travelId);
|
console.info('TRAVEL_CLONE_WITH_ENTRIES');
|
||||||
await travelBefore.updateAttributes({
|
// const yesterday = Date.vnNew();
|
||||||
shipped: yesterday,
|
// yesterday.setDate(yesterday.getDate() - 1);
|
||||||
landed: yesterday
|
|
||||||
});
|
|
||||||
|
|
||||||
newTravelId = await models.Travel.cloneWithEntries(ctx, travelId);
|
// travelBefore = await models.Travel.findById(travelId);
|
||||||
const travelEntries = await models.Entry.find({
|
// await travelBefore.updateAttributes({
|
||||||
where: {
|
// shipped: yesterday,
|
||||||
|
// landed: yesterday
|
||||||
|
// });
|
||||||
|
// const filter = {
|
||||||
|
// order: 'landed ASC, shipped ASC, travelFk, loadPriority, agencyModeFk, evaNotes',
|
||||||
|
// };
|
||||||
|
// const agencyModeFk_BEFORE = await app.models.Travel.extraCommunityFilter({
|
||||||
|
// args: {
|
||||||
|
// agencyModeFk: 1
|
||||||
|
// }
|
||||||
|
// }, filter);
|
||||||
|
// const cargoSupplierFk_BEFORE = await app.models.Travel.extraCommunityFilter({
|
||||||
|
// args: {
|
||||||
|
// cargoSupplierFk: 1
|
||||||
|
// }
|
||||||
|
// }, filter);
|
||||||
|
|
||||||
|
const options = {transaction: tx};
|
||||||
|
newTravelId = await models.Travel.cloneWithEntries(ctx, travelId, options);
|
||||||
|
const travelEntries = await models.Entry.find({
|
||||||
|
where: {
|
||||||
|
travelFk: newTravelId
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
const newTravel = await models.Travel.findById(travelId, options);
|
||||||
|
|
||||||
|
expect(newTravelId).not.toEqual(travelId);
|
||||||
|
expect(newTravel.ref).toEqual('fifth travel');
|
||||||
|
expect(newTravel.warehouseInFk).toEqual(warehouseThree);
|
||||||
|
expect(newTravel.warehouseOutFk).toEqual(warehouseThree);
|
||||||
|
expect(newTravel.agencyModeFk).toEqual(agencyModeOne);
|
||||||
|
expect(travelEntries.length).toBeGreaterThan(0);
|
||||||
|
await models.Entry.destroyAll({
|
||||||
travelFk: newTravelId
|
travelFk: newTravelId
|
||||||
}
|
}, options);
|
||||||
});
|
|
||||||
|
|
||||||
const newTravel = await models.Travel.findById(travelId);
|
// Destroy new travel
|
||||||
|
await models.Travel.destroyById(newTravelId, options);
|
||||||
|
// const agencyModeFk_AFTER = await app.models.Travel.extraCommunityFilter({
|
||||||
|
// args: {
|
||||||
|
// agencyModeFk: 1
|
||||||
|
// }
|
||||||
|
// }, filter);
|
||||||
|
// const cargoSupplierFk_AFTER = await app.models.Travel.extraCommunityFilter({
|
||||||
|
// args: {
|
||||||
|
// cargoSupplierFk: 1
|
||||||
|
// }
|
||||||
|
// }, filter);
|
||||||
|
|
||||||
expect(newTravelId).not.toEqual(travelId);
|
// expect(agencyModeFk_BEFORE.length).toEqual(agencyModeFk_AFTER.length);
|
||||||
expect(newTravel.ref).toEqual('fifth travel');
|
// expect(cargoSupplierFk_BEFORE.length).toEqual(cargoSupplierFk_AFTER.length);
|
||||||
expect(newTravel.warehouseInFk).toEqual(warehouseThree);
|
} catch (e) {
|
||||||
expect(newTravel.warehouseOutFk).toEqual(warehouseThree);
|
if (tx) await tx.rollback();
|
||||||
expect(newTravel.agencyModeFk).toEqual(agencyModeOne);
|
throw e;
|
||||||
expect(travelEntries.length).toBeGreaterThan(0);
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue