const app = require('vn-loopback/server/server');

describe('dms downloadFile()', () => {
    let dmsId = 1;

    it('should return a response for an employee with text content-type', async() => {
        let workerId = 1107;
        let ctx = {req: {accessToken: {userId: workerId}}};
        const result = await app.models.Dms.downloadFile(ctx, dmsId);

        expect(result[1]).toEqual('text/plain');
    });

    it('should return an error for a user without enough privileges', async() => {
        let clientId = 1101;
        let ctx = {req: {accessToken: {userId: clientId}}};

        let error;
        await app.models.Dms.downloadFile(ctx, dmsId).catch(e => {
            error = e;
        }).finally(() => {
            expect(error.message).toEqual(`You don't have enough privileges`);
        });

        expect(error).toBeDefined();
    });
});