Skip to content

Commit 0514ee7

Browse files
feat: add fn _isEnterpriseUser (#35)
1 parent cbd19ac commit 0514ee7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ class ScmRouter extends Scm {
478478
_openPr(config) {
479479
return this.chooseScm(config).then(scm => scm.openPr(config));
480480
}
481+
482+
/**
483+
* Check if user belongs to an enterprise
484+
* @method _isEnterpriseUser
485+
* @param {Object} config Configuration
486+
* @param {String} config.scmContext Name of scm context
487+
* @return {Boolean} True if user belongs to an enterprise
488+
*/
489+
_isEnterpriseUser(config) {
490+
return this.chooseScm(config).then(scm => scm.isEnterpriseUser(config));
491+
}
481492
}
482493

483494
module.exports = ScmRouter;

test/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('index test', () => {
7575
mock.getReadOnlyInfo = sinon.stub().returns(plugin);
7676
mock.autoDeployKeyGenerationEnabled = sinon.stub().returns(plugin);
7777
mock.getWebhookEventsMapping = sinon.stub().returns({ pr: 'pull_request' });
78+
mock.isEnterpriseUser = sinon.stub().returns(true);
7879

7980
return mock;
8081
};
@@ -964,4 +965,17 @@ describe('index test', () => {
964965
assert.calledWith(exampleScm.openPr, config);
965966
}));
966967
});
968+
969+
describe('_isEnterpriseUser', () => {
970+
const config = { scmContext: exampleScmContext };
971+
972+
it('call origin _isEnterpriseUser', () =>
973+
scm._isEnterpriseUser(config).then(result => {
974+
assert.strictEqual(result, true);
975+
assert.notCalled(scmGithub.isEnterpriseUser);
976+
assert.notCalled(scmGitlab.isEnterpriseUser);
977+
assert.calledOnce(exampleScm.isEnterpriseUser);
978+
assert.calledWith(exampleScm.isEnterpriseUser, config);
979+
}));
980+
});
967981
});

0 commit comments

Comments
 (0)