refs #2687 feat: fix test suite

This commit is contained in:
Javier Segarra 2023-12-12 07:33:08 +01:00
parent c0d2e0511d
commit 30dbc8a587
1 changed files with 60 additions and 20 deletions

View File

@ -46,32 +46,72 @@ describe('Travel cloneWithEntries()', () => {
// });
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 agencyModeOne = 1;
const yesterday = Date.vnNew();
yesterday.setDate(yesterday.getDate() - 1);
try {
// pending('#2687 - Cannot make a data rollback because of the triggers');
travelBefore = await models.Travel.findById(travelId);
await travelBefore.updateAttributes({
shipped: yesterday,
landed: yesterday
});
console.info('TRAVEL_CLONE_WITH_ENTRIES');
// const yesterday = Date.vnNew();
// yesterday.setDate(yesterday.getDate() - 1);
newTravelId = await models.Travel.cloneWithEntries(ctx, travelId);
const travelEntries = await models.Entry.find({
where: {
// travelBefore = await models.Travel.findById(travelId);
// await travelBefore.updateAttributes({
// 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
}
});
}, 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(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);
// expect(agencyModeFk_BEFORE.length).toEqual(agencyModeFk_AFTER.length);
// expect(cargoSupplierFk_BEFORE.length).toEqual(cargoSupplierFk_AFTER.length);
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
});
});