salix/back/models/specs/dms.spec.js

54 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2023-01-24 08:04:43 +00:00
const {models} = require('vn-loopback/server/server');
2020-04-03 15:52:47 +00:00
describe('Dms', () => {
2023-01-24 08:04:43 +00:00
const Dms = models.Dms;
2020-04-03 15:52:47 +00:00
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 {
2023-01-24 08:04:43 +00:00
await models.Dms.getFile('NotExistentId');
2020-04-03 15:52:47 +00:00
} 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}}};
2020-04-03 15:52:47 +00:00
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}}};
2020-04-03 15:52:47 +00:00
const result = await Dms.checkRole(ctx, dmsId);
expect(result).toBeFalsy();
});
});
});