salix/modules/ticket/back/methods/sale/specs/updateConcept.spec.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

const models = require('vn-loopback/server/server').models;
2023-03-23 09:05:02 +00:00
const LoopBackContext = require('loopback-context');
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
});
});
const ctx = {req: {accessToken: {userId: 9}}};
const saleId = 25;
it('should throw if ID was undefined', async() => {
const tx = await models.Sale.beginTransaction({});
let error;
try {
const options = {transaction: tx};
const newConcept = 'not going to heppen';
await models.Sale.updateConcept(ctx, undefined, newConcept, options);
await tx.rollback();
2019-09-30 11:02:11 +00:00
} catch (e) {
await tx.rollback();
error = e;
2019-09-30 11:02:11 +00:00
}
expect(error).toBeDefined();
});
it('should update the sale concept', async() => {
const tx = await models.Sale.beginTransaction({});
try {
const options = {transaction: tx};
const newConcept = 'I am the new concept';
let response = await models.Sale.updateConcept(ctx, saleId, newConcept, options);
expect(response.concept).toEqual(newConcept);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});