salix/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js

77 lines
2.7 KiB
JavaScript

const app = require(`${servicesDir}/ticket/server/server`);
describe('ticket componentUpdate()', () => {
let firstvalueBeforeChange;
let secondvalueBeforeChange;
let componentOfSaleSeven = `SELECT value FROM vn.saleComponent
WHERE saleFk = 7 AND componentFk = 15`;
let componentOfSaleEight = `SELECT value FROM vn.saleComponent
WHERE saleFk = 8 AND componentFk = 15`;
const toDay = new Date();
beforeAll(async() => {
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
firstvalueBeforeChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
secondvalueBeforeChange = componentValue.value;
});
it('should change the agencyMode to modify the sale components value', async() => {
let firstvalueAfterChange;
let secondvalueAfterChange;
let data = {
clientFk: 101,
agencyModeFk: 8,
addressFk: 121,
warehouseFk: 1,
shipped: toDay,
landed: toDay,
isDeleted: false,
hasToBeUnrouted: false,
option: 1
};
let ctx = {req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(11, data, ctx);
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
firstvalueAfterChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
secondvalueAfterChange = componentValue.value;
expect(firstvalueBeforeChange).not.toEqual(firstvalueAfterChange);
expect(secondvalueBeforeChange).not.toEqual(secondvalueAfterChange);
});
it('should change the agencyMode to go back to the originals sale components value', async() => {
let firstvalueAfterChange;
let secondvalueAfterChange;
let data = {
clientFk: 101,
agencyModeFk: 7,
addressFk: 121,
warehouseFk: 1,
shipped: toDay,
landed: toDay,
isDeleted: false,
hasToBeUnrouted: false,
option: 1
};
let ctx = {req: {accessToken: {userId: 101}}};
await app.models.Ticket.componentUpdate(11, data, ctx);
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
firstvalueAfterChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
secondvalueAfterChange = componentValue.value;
expect(firstvalueBeforeChange).toEqual(firstvalueAfterChange);
expect(secondvalueBeforeChange).toEqual(secondvalueAfterChange);
});
});