const app = require('vn-loopback/server/server'); describe('sale canEdit()', () => { it('should return true if the role is production regardless of the saleTrackings', async() => { const productionUserID = 49; let ctx = {req: {accessToken: {userId: productionUserID}}}; const sales = [{id: 3}]; const result = await app.models.Sale.canEdit(ctx, sales); expect(result).toEqual(true); }); it('should return true if the role is not production and none of the sales has saleTracking', async() => { const salesPersonUserID = 18; let ctx = {req: {accessToken: {userId: salesPersonUserID}}}; const sales = [{id: 10}]; const result = await app.models.Sale.canEdit(ctx, sales); expect(result).toEqual(true); }); it('should return false if any of the sales has a saleTracking record', async() => { const salesPersonUserID = 18; let ctx = {req: {accessToken: {userId: salesPersonUserID}}}; const sales = [{id: 3}]; const result = await app.models.Sale.canEdit(ctx, sales); expect(result).toEqual(false); }); });