Skip to content

Commit

Permalink
feat: add fn _isEnterpriseUser (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamstyz4ever authored Apr 2, 2024
1 parent cbd19ac commit 0514ee7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@ class ScmRouter extends Scm {
_openPr(config) {
return this.chooseScm(config).then(scm => scm.openPr(config));
}

/**
* Check if user belongs to an enterprise
* @method _isEnterpriseUser
* @param {Object} config Configuration
* @param {String} config.scmContext Name of scm context
* @return {Boolean} True if user belongs to an enterprise
*/
_isEnterpriseUser(config) {
return this.chooseScm(config).then(scm => scm.isEnterpriseUser(config));
}
}

module.exports = ScmRouter;
14 changes: 14 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('index test', () => {
mock.getReadOnlyInfo = sinon.stub().returns(plugin);
mock.autoDeployKeyGenerationEnabled = sinon.stub().returns(plugin);
mock.getWebhookEventsMapping = sinon.stub().returns({ pr: 'pull_request' });
mock.isEnterpriseUser = sinon.stub().returns(true);

return mock;
};
Expand Down Expand Up @@ -964,4 +965,17 @@ describe('index test', () => {
assert.calledWith(exampleScm.openPr, config);
}));
});

describe('_isEnterpriseUser', () => {
const config = { scmContext: exampleScmContext };

it('call origin _isEnterpriseUser', () =>
scm._isEnterpriseUser(config).then(result => {
assert.strictEqual(result, true);
assert.notCalled(scmGithub.isEnterpriseUser);
assert.notCalled(scmGitlab.isEnterpriseUser);
assert.calledOnce(exampleScm.isEnterpriseUser);
assert.calledWith(exampleScm.isEnterpriseUser, config);
}));
});
});

0 comments on commit 0514ee7

Please sign in to comment.