const sinon = require('sinon');
const assert = require('assert');

const dbGateway = {
    getPermissionForUser(perm, userId) {
        return query(
            'select has_permission ' +
            'from permissions ' +
            'where permission = $ and user_id = $;',
            perm, userId);
    },
};

function hasReadPermission(userId) {
    return dbGateway.getPermissionForUser('read_files', userId);
}

describe('hasPermission', () => {
    it('should return true if the user has permission', () => {
        sinon.stub(dbGateway, 'getPermissionForUser').returns(true);
        const result = hasReadPermission(123);
        assert.equal(result, true);
    });
});