Skip to content

Commit

Permalink
fix(1079): Fix autoDeployKeyGenerationEnabled to not return a promise (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
supra08 authored Aug 5, 2020
1 parent 4760845 commit bf358fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ class ScmRouter extends Scm {

/**
* Returns whether auto deploy key generation is enabled on or not
* @method _autoDeployKeyGenerationEnabled
* @method autoDeployKeyGenerationEnabled
* @param {Object} config Configuration
* @param {String} config.scmContext Name of scm context
* @return {Promise} Resolves when operation completed without failure
* @return {Boolean} Resolves when operation completed without failure
*/
_autoDeployKeyGenerationEnabled(config) {
return this.chooseScm(config).then(scm => scm.autoDeployKeyGenerationEnabled(config));
autoDeployKeyGenerationEnabled(config) {
return this.scms[config.scmContext].autoDeployKeyGenerationEnabled();
}

/**
* Parse the url for a repo for the specific source control
* Generate and add the public deploy key to the specific scm
* @method _addDeployKey
* @param {Object} config Configuration
* @param {String} config.scmContext Name of scm context
Expand Down
36 changes: 17 additions & 19 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('index test', () => {
mock.canHandleWebhook = sinon.stub().resolves(true);
mock.getScmContexts = sinon.stub().returns([`${plugin}.context`]);
mock.getDisplayName = sinon.stub().returns(plugin);
mock.autoDeployKeyGenerationEnabled = sinon.stub().returns(plugin);

return mock;
};
Expand Down Expand Up @@ -582,25 +583,6 @@ describe('index test', () => {
});
});

describe('_autoDeployKeyGenerationEnabled', () => {
const config = { scmContext: 'example.context' };

it('call origin autoDeployKeyGenerationEnabled', () => {
const scmGithub = scm.scms['github.context'];
const exampleScm = scm.scms['example.context'];
const scmGitlab = scm.scms['gitlab.context'];

return scm._autoDeployKeyGenerationEnabled(config)
.then((result) => {
assert.strictEqual(result, 'example');
assert.notCalled(scmGithub.autoDeployKeyGenerationEnabled);
assert.notCalled(scmGitlab.autoDeployKeyGenerationEnabled);
assert.calledOnce(exampleScm.autoDeployKeyGenerationEnabled);
assert.calledWith(exampleScm.autoDeployKeyGenerationEnabled, config);
});
});
});

describe('_parseUrl', () => {
const config = { scmContext: 'example.context' };

Expand Down Expand Up @@ -1003,6 +985,22 @@ describe('index test', () => {
});
});

describe('autoDeployKeyGenerationEnabled', () => {
const config = { scmContext: 'example.context' };

it('call origin autoDeployKeyGenerationEnabled', () => {
const scmGithub = scm.scms['github.context'];
const exampleScm = scm.scms['example.context'];
const scmGitlab = scm.scms['gitlab.context'];
const result = scm.autoDeployKeyGenerationEnabled(config);

assert.strictEqual(result, 'example');
assert.notCalled(scmGithub.autoDeployKeyGenerationEnabled);
assert.notCalled(scmGitlab.autoDeployKeyGenerationEnabled);
assert.calledOnce(exampleScm.autoDeployKeyGenerationEnabled);
});
});

describe('_getBranchList', () => {
const config = { scmContext: 'example.context' };

Expand Down

0 comments on commit bf358fe

Please sign in to comment.