Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for getLocalAccessKey function #5948

Merged
merged 1 commit into from Mar 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
84 changes: 84 additions & 0 deletions lib/classes/Utils.test.js
Expand Up @@ -829,4 +829,88 @@ describe('Utils', () => {
});
});
});

describe('#getLocalAccessKey()', () => {
let getConfigStub;
let getGlobalConfigStub;

beforeEach(() => {
getConfigStub = sinon.stub(configUtils, 'getConfig');
getGlobalConfigStub = sinon.stub(configUtils, 'getGlobalConfig');
});

afterEach(() => {
configUtils.getConfig.restore();
configUtils.getGlobalConfig.restore();
});

it('should return false if a user could not be found globally', () => {
getConfigStub.returns({
userId: 123456,
});
getGlobalConfigStub.returns({});

const res = utils.getLocalAccessKey();

expect(res).to.equal(false);
});

it('should return false if a user could be found globally but no locally', () => {
getConfigStub.returns({});
getGlobalConfigStub.returns({
users: {
123456: {
dashboard: {
accessKey: 'd45hb04rd4cc3ssk3y',
},
},
},
});

const res = utils.getLocalAccessKey();
expect(res).to.equal(false);
});

it('should return false if a user could be found but the dashboard config is missing', () => {
getConfigStub.returns({ userId: 123456 });
getGlobalConfigStub.returns({
users: {
123456: {},
},
});

const res = utils.getLocalAccessKey();
expect(res).to.equal(false);
});

it('should return false if a user could be found but the accessKey config is missing', () => {
getConfigStub.returns({ userId: 123456 });
getGlobalConfigStub.returns({
users: {
123456: {
dashboard: {},
},
},
});

const res = utils.getLocalAccessKey();
expect(res).to.equal(false);
});

it('should return the users dasboard access key if config can be found', () => {
getConfigStub.returns({ userId: 123456 });
getGlobalConfigStub.returns({
users: {
123456: {
dashboard: {
accessKey: 'd45hb04rd4cc3ssk3y',
},
},
},
});

const res = utils.getLocalAccessKey();
expect(res).to.equal('d45hb04rd4cc3ssk3y');
});
});
});