feat: refs #8151 moveExpeditions #3200
|
@ -80,11 +80,17 @@ module.exports = Self => {
|
||||||
const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions);
|
const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions);
|
||||||
promises.push(expeditionUpdated);
|
promises.push(expeditionUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
await models.Ticket.updateAll({id: ticket.id}, {packages: promises.length}, myOptions);
|
||||||
|
|||||||
|
const state = await models.State.findOne({where: {code: 'PACKED'}});
|
||||||
|
|
||||||
|
await models.Ticket.state(ctx, {
|
||||||
|
ticketFk: ticket.id,
|
||||||
|
stateFk: state.id,
|
||||||
|
userFk: ctx.req.accessToken.userId
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return ticket;
|
return ticket;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
|
@ -17,14 +17,55 @@ describe('ticket moveExpeditions()', () => {
|
||||||
agencyModeId: 1,
|
agencyModeId: 1,
|
||||||
routeId: null,
|
routeId: null,
|
||||||
expeditionIds: [1, 2]
|
expeditionIds: [1, 2]
|
||||||
|
|
||||||
};
|
};
|
||||||
|
const newestTicketIdInFixtures = await models.Ticket.findOne({
|
||||||
|
order: 'id DESC'
|
||||||
|
}, options);
|
||||||
const ticket = await models.Expedition.moveExpeditions(ctx, options);
|
const ticket = await models.Expedition.moveExpeditions(ctx, options);
|
||||||
|
|
||||||
const newestTicketIdInFixtures = 27;
|
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures.id);
|
||||||
|
|
||||||
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures);
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should move expeditions to a new ticket, set state to PACKED, and update packages count correctly', async() => {
|
||||||
|
const tx = await models.Expedition.beginTransaction({});
|
||||||
|
const myCtx = ctx;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
myCtx.args = {
|
||||||
|
clientId: 1101,
|
||||||
|
landed: Date.vnNew(),
|
||||||
|
warehouseId: 1,
|
||||||
|
addressId: 121,
|
||||||
|
agencyModeId: 1,
|
||||||
|
routeId: null,
|
||||||
|
expeditionIds: [1, 2]
|
||||||
|
};
|
||||||
|
|
||||||
|
const newestTicketIdInFixtures = await models.Ticket.findOne({
|
||||||
|
order: 'id DESC'
|
||||||
|
}, options);
|
||||||
|
const ticket = await models.Expedition.moveExpeditions(myCtx, options);
|
||||||
guillermo marked this conversation as resolved
jgallego
commented
fes este id relatiu, sino quan creen fixturs trencara este test fes este id relatiu, sino quan creen fixturs trencara este test
|
|||||||
|
|
||||||
|
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures.id);
|
||||||
|
|
||||||
|
const updatedTicket = await models.Ticket.findById(ticket.id, null, options);
|
||||||
|
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
|
||||||
|
|
||||||
|
const state = await models.TicketState.findOne({where: {ticketFk: ticket.id}}, options);
|
||||||
|
|
||||||
|
expect(state.stateFk).toBe(packedState.id);
|
||||||
|
expect(state.userFk).toBe(myCtx.req.accessToken.userId);
|
||||||
|
|
||||||
|
const expectedPackagesCount = myCtx.args.expeditionIds.length;
|
||||||
|
|
||||||
|
expect(updatedTicket.$packages).toBe(expectedPackagesCount);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -33,4 +74,3 @@ describe('ticket moveExpeditions()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
no he utilizado ticket.updateAttribute porque me daba
error val.slice is not a function
en una linea de código de la libreria sqlstring