{"size": 1005, "ext": "js", "max_stars_repo_path": "test/hooks/check-role-usage.test.js", "max_stars_repo_name": "ronnamaeffirmo/fhcs", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/hooks/check-role-usage.test.js", "max_issues_repo_name": "ronnamaeffirmo/fhcs", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/hooks/check-role-usage.test.js", "max_forks_repo_name": "ronnamaeffirmo/fhcs", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.8409090909, "max_line_length": 68, "alphanum_fraction": 0.6049751244}
const assert = require('assert');
const feathers = require('@feathersjs/feathers');
const checkRoleUsage = require('../../src/hooks/check-role-usage');
const sinon = require('sinon')

describe('\'check role usage\' hook', () => {
  const serviceStub = sinon.stub()
  const findStub = sinon.stub()
  const hookStub = sinon.stub()

  const appStub = {
    service: serviceStub
  }

  appStub.service.returns({
    find: findStub,
    hooks: hookStub,
  })

  beforeEach(() => {
    findStub.returns({
      id: '123'
    })

    hookStub.returns({
      before: checkRoleUsage()
    })
    appStub.service('dummy').hooks()
  });

  it('runs the hook', async () => {
    const result = await appStub.service('dummy').find('123');
    
    assert.deepEqual(result, { id: '123' });
  });

  it('should return an error when parameter is empty', async () => {
    try {
      const result = await app.service('dummy').find();
    } catch(err) {
      assert.strictEqual(err.name, 'ReferenceError')
    }
  })
});