2021-09-29 06:27:18 +00:00
|
|
|
const models = require('vn-loopback/server/server').models;
|
2023-03-23 09:05:02 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
2019-09-26 07:05:18 +00:00
|
|
|
|
|
|
|
describe('sale updateConcept()', () => {
|
2023-03-23 09:05:02 +00:00
|
|
|
beforeAll(async() => {
|
|
|
|
const activeCtx = {
|
|
|
|
accessToken: {userId: 9},
|
|
|
|
http: {
|
|
|
|
req: {
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
|
|
active: activeCtx
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-26 07:14:18 +00:00
|
|
|
const ctx = {req: {accessToken: {userId: 9}}};
|
2022-10-05 13:13:36 +00:00
|
|
|
const saleId = 25;
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
it('should throw if ID was undefined', async() => {
|
|
|
|
const tx = await models.Sale.beginTransaction({});
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
let error;
|
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
const newConcept = 'not going to heppen';
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
await models.Sale.updateConcept(ctx, undefined, newConcept, options);
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
await tx.rollback();
|
2019-09-30 11:02:11 +00:00
|
|
|
} catch (e) {
|
2021-09-29 06:27:18 +00:00
|
|
|
await tx.rollback();
|
|
|
|
error = e;
|
2019-09-30 11:02:11 +00:00
|
|
|
}
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
expect(error).toBeDefined();
|
2019-09-26 07:05:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should update the sale concept', async() => {
|
2021-09-29 06:27:18 +00:00
|
|
|
const tx = await models.Sale.beginTransaction({});
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
try {
|
|
|
|
const options = {transaction: tx};
|
|
|
|
|
|
|
|
const newConcept = 'I am the new concept';
|
|
|
|
|
|
|
|
let response = await models.Sale.updateConcept(ctx, saleId, newConcept, options);
|
2019-09-26 07:05:18 +00:00
|
|
|
|
2021-09-29 06:27:18 +00:00
|
|
|
expect(response.concept).toEqual(newConcept);
|
|
|
|
|
|
|
|
await tx.rollback();
|
|
|
|
} catch (e) {
|
|
|
|
await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2019-09-26 07:05:18 +00:00
|
|
|
});
|
|
|
|
});
|