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

75 lines
2.6 KiB
JavaScript
Raw Normal View History

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`;
2018-10-03 09:40:51 +00:00
const today = new Date();
let ticketId = 11;
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 data = {
2018-08-10 09:40:48 +00:00
clientFk: 101,
agencyModeFk: 8,
2018-06-05 10:49:33 +00:00
addressFk: 121,
warehouseFk: 1,
2018-10-03 09:40:51 +00:00
shipped: today,
landed: today,
2018-08-10 09:40:48 +00:00
isDeleted: false,
hasToBeUnrouted: false,
option: 1
};
let ctx = {req: {accessToken: {userId: 101}}};
2018-10-03 09:40:51 +00:00
await app.models.Ticket.componentUpdate(ticketId, data, ctx);
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleSeven);
2018-10-03 09:40:51 +00:00
let firstvalueAfterChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
2018-10-03 09:40:51 +00:00
let 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 data = {
clientFk: 101,
agencyModeFk: 7,
addressFk: 121,
warehouseFk: 1,
2018-10-03 09:40:51 +00:00
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);
2018-10-03 09:40:51 +00:00
let firstvalueAfterChange = componentValue.value;
[componentValue] = await app.models.SaleComponent.rawSql(componentOfSaleEight);
2018-10-03 09:40:51 +00:00
let secondvalueAfterChange = componentValue.value;
2018-08-10 09:40:48 +00:00
expect(firstvalueBeforeChange).toEqual(firstvalueAfterChange);
expect(secondvalueBeforeChange).toEqual(secondvalueAfterChange);
});
});