2022-10-10 10:56:03 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
|
|
|
|
2024-11-14 09:45:28 +00:00
|
|
|
fdescribe('ticket moveExpeditions()', () => {
|
2024-06-14 06:39:57 +00:00
|
|
|
const ctx = beforeAll.getCtx();
|
2023-04-12 10:33:14 +00:00
|
|
|
|
2022-10-20 06:41:00 +00:00
|
|
|
it('should move the selected expeditions to new ticket', async() => {
|
2022-10-10 10:56:03 +00:00
|
|
|
const tx = await models.Expedition.beginTransaction({});
|
2024-06-11 11:17:19 +00:00
|
|
|
const myCtx = ctx;
|
2022-10-10 10:56:03 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2022-10-20 06:41:00 +00:00
|
|
|
myCtx.args = {
|
|
|
|
clientId: 1101,
|
2023-01-16 14:18:24 +00:00
|
|
|
landed: Date.vnNew(),
|
2022-10-20 06:41:00 +00:00
|
|
|
warehouseId: 1,
|
|
|
|
addressId: 121,
|
|
|
|
agencyModeId: 1,
|
|
|
|
routeId: null,
|
|
|
|
expeditionIds: [1, 2]
|
|
|
|
};
|
2024-11-14 09:45:28 +00:00
|
|
|
const newestTicketIdInFixtures = await models.Ticket.findOne({
|
|
|
|
order: 'id DESC'
|
|
|
|
}, options);
|
2024-06-11 11:17:19 +00:00
|
|
|
const ticket = await models.Expedition.moveExpeditions(ctx, options);
|
2022-10-20 06:41:00 +00:00
|
|
|
|
2024-11-14 09:45:28 +00:00
|
|
|
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures.id);
|
2022-10-10 10:56:03 +00:00
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-11-13 13:04:02 +00:00
|
|
|
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]
|
|
|
|
};
|
|
|
|
|
2024-11-14 09:45:28 +00:00
|
|
|
const newestTicketIdInFixtures = await models.Ticket.findOne({
|
|
|
|
order: 'id DESC'
|
|
|
|
}, options);
|
2024-11-13 13:04:02 +00:00
|
|
|
const ticket = await models.Expedition.moveExpeditions(myCtx, options);
|
|
|
|
|
2024-11-14 09:45:28 +00:00
|
|
|
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures.id);
|
2024-11-13 13:04:02 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|