const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('sale updateConcept()', () => { 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(); } catch (e) { await tx.rollback(); error = e; } 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; } }); });