Skip to content

Commit bf358fe

Browse files
authored
fix(1079): Fix autoDeployKeyGenerationEnabled to not return a promise (#25)
* feat(scm-router): Add addDeployKey method * feat(): add checkAutoDeployKey function * feat(): add tests for checkAutoDeployKeyGeneration * refactor(): change function name to autoDeployKeyGenerationEnabled * fix(): Fix autoDeployKeyGenerationEnabled to not return a promise
1 parent 4760845 commit bf358fe

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,17 @@ class ScmRouter extends Scm {
156156

157157
/**
158158
* Returns whether auto deploy key generation is enabled on or not
159-
* @method _autoDeployKeyGenerationEnabled
159+
* @method autoDeployKeyGenerationEnabled
160160
* @param {Object} config Configuration
161161
* @param {String} config.scmContext Name of scm context
162-
* @return {Promise} Resolves when operation completed without failure
162+
* @return {Boolean} Resolves when operation completed without failure
163163
*/
164-
_autoDeployKeyGenerationEnabled(config) {
165-
return this.chooseScm(config).then(scm => scm.autoDeployKeyGenerationEnabled(config));
164+
autoDeployKeyGenerationEnabled(config) {
165+
return this.scms[config.scmContext].autoDeployKeyGenerationEnabled();
166166
}
167167

168168
/**
169-
* Parse the url for a repo for the specific source control
169+
* Generate and add the public deploy key to the specific scm
170170
* @method _addDeployKey
171171
* @param {Object} config Configuration
172172
* @param {String} config.scmContext Name of scm context

test/index.test.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('index test', () => {
6565
mock.canHandleWebhook = sinon.stub().resolves(true);
6666
mock.getScmContexts = sinon.stub().returns([`${plugin}.context`]);
6767
mock.getDisplayName = sinon.stub().returns(plugin);
68+
mock.autoDeployKeyGenerationEnabled = sinon.stub().returns(plugin);
6869

6970
return mock;
7071
};
@@ -582,25 +583,6 @@ describe('index test', () => {
582583
});
583584
});
584585

585-
describe('_autoDeployKeyGenerationEnabled', () => {
586-
const config = { scmContext: 'example.context' };
587-
588-
it('call origin autoDeployKeyGenerationEnabled', () => {
589-
const scmGithub = scm.scms['github.context'];
590-
const exampleScm = scm.scms['example.context'];
591-
const scmGitlab = scm.scms['gitlab.context'];
592-
593-
return scm._autoDeployKeyGenerationEnabled(config)
594-
.then((result) => {
595-
assert.strictEqual(result, 'example');
596-
assert.notCalled(scmGithub.autoDeployKeyGenerationEnabled);
597-
assert.notCalled(scmGitlab.autoDeployKeyGenerationEnabled);
598-
assert.calledOnce(exampleScm.autoDeployKeyGenerationEnabled);
599-
assert.calledWith(exampleScm.autoDeployKeyGenerationEnabled, config);
600-
});
601-
});
602-
});
603-
604586
describe('_parseUrl', () => {
605587
const config = { scmContext: 'example.context' };
606588

@@ -1003,6 +985,22 @@ describe('index test', () => {
1003985
});
1004986
});
1005987

988+
describe('autoDeployKeyGenerationEnabled', () => {
989+
const config = { scmContext: 'example.context' };
990+
991+
it('call origin autoDeployKeyGenerationEnabled', () => {
992+
const scmGithub = scm.scms['github.context'];
993+
const exampleScm = scm.scms['example.context'];
994+
const scmGitlab = scm.scms['gitlab.context'];
995+
const result = scm.autoDeployKeyGenerationEnabled(config);
996+
997+
assert.strictEqual(result, 'example');
998+
assert.notCalled(scmGithub.autoDeployKeyGenerationEnabled);
999+
assert.notCalled(scmGitlab.autoDeployKeyGenerationEnabled);
1000+
assert.calledOnce(exampleScm.autoDeployKeyGenerationEnabled);
1001+
});
1002+
});
1003+
10061004
describe('_getBranchList', () => {
10071005
const config = { scmContext: 'example.context' };
10081006

0 commit comments

Comments
 (0)