#2687 - Travel CloneWithEntries #1887
|
@ -46,26 +46,43 @@ 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);
|
||||
// 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
|
||||
}
|
||||
});
|
||||
|
||||
const newTravel = await models.Travel.findById(travelId);
|
||||
}, options);
|
||||
const newTravel = await models.Travel.findById(travelId, options);
|
||||
|
||||
expect(newTravelId).not.toEqual(travelId);
|
||||
expect(newTravel.ref).toEqual('fifth travel');
|
||||
|
@ -73,5 +90,28 @@ describe('Travel cloneWithEntries()', () => {
|
|||
expect(newTravel.warehouseOutFk).toEqual(warehouseThree);
|
||||
expect(newTravel.agencyModeFk).toEqual(agencyModeOne);
|
||||
expect(travelEntries.length).toBeGreaterThan(0);
|
||||
await models.Entry.destroyAll({
|
||||
travelFk: newTravelId
|
||||
}, options);
|
||||
|
||||
// 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(agencyModeFk_BEFORE.length).toEqual(agencyModeFk_AFTER.length);
|
||||
// expect(cargoSupplierFk_BEFORE.length).toEqual(cargoSupplierFk_AFTER.length);
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue