54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
const {models} = require('vn-loopback/server/server');
|
|
describe('Dms', () => {
|
|
const Dms = 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 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: 1107}}};
|
|
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: 1101}}};
|
|
const result = await Dms.checkRole(ctx, dmsId);
|
|
|
|
expect(result).toBeFalsy();
|
|
});
|
|
});
|
|
});
|
|
|