const app = require('vn-loopback/server/server'); describe('Dms', () => { const Dms = app.models.Dms; describe('getFile()', () => { it('should return a response with text content-type', async() => { const result = await Dms.getFile(1); expect(result[1]).toEqual('text/plain'); }); it('should return an error for a file does not exists', async() => { let error = {}; try { await Dms.getFile(6); } catch (e) { error = e; } expect(error.statusCode).toBe(404); }); it('should return an error for a record does not exists', async() => { let error = {}; try { await app.models.Dms.getFile('NotExistentId'); } catch (e) { error = e; } expect(error.statusCode).not.toBe(404); expect(error).toEqual(jasmine.any(Error)); }); }); describe('checkRole()', () => { const dmsId = 1; it('should return a true for an employee with permission', async() => { let ctx = {req: {accessToken: {userId: 107}}}; const result = await Dms.checkRole(ctx, dmsId); expect(result).toBeTruthy(); }); it('should return false for an employee without permission', async() => { let ctx = {req: {accessToken: {userId: 101}}}; const result = await Dms.checkRole(ctx, dmsId); expect(result).toBeFalsy(); }); }); });