Skip to content

Commit

Permalink
feat(1079): Router functions for deploy keys pipeline [2] (#24)
Browse files Browse the repository at this point in the history
* feat(scm-router): Add addDeployKey method

* feat(): add checkAutoDeployKey function

* feat(): add tests for checkAutoDeployKeyGeneration

* refactor(): change function name to autoDeployKeyGenerationEnabled
  • Loading branch information
supra08 authored Aug 4, 2020
1 parent c135512 commit 4760845
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ class ScmRouter extends Scm {
return this.chooseScm(config).then(scm => scm.addWebhook(config));
}

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

/**
* Parse the url for a repo for the specific source control
* @method _addDeployKey
Expand Down
20 changes: 20 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('index test', () => {
'dummyRejectFunction',
'addWebhook',
'addDeployKey',
'autoDeployKeyGenerationEnabled',
'parseUrl',
'parseHook',
'getCheckoutCommand',
Expand Down Expand Up @@ -581,6 +582,25 @@ 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

0 comments on commit 4760845

Please sign in to comment.