salix/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js

77 lines
2.6 KiB
JavaScript

const models = require('vn-loopback/server/server').models;
fdescribe('ticket moveExpeditions()', () => {
const ctx = beforeAll.getCtx();
it('should move the selected expeditions to new ticket', 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(ctx, options);
expect(ticket.id).toBeGreaterThan(newestTicketIdInFixtures.id);
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);
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();
} catch (e) {
await tx.rollback();
throw e;
}
});
});