Skip to content

Commit

Permalink
fix: creating a new self-hosted skill fails with TypeError (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chih-Ying authored Apr 15, 2020
1 parent 11f808a commit b1560dc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
4 changes: 1 addition & 3 deletions lib/commands/new/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const ResourcesConfig = require('@src/model/resources-config');
const CONSTANTS = require('@src/utils/constants');
const stringUtils = require('@src/utils/string-utils');

const ui = require('./ui');

module.exports = {
downloadTemplateFromGit,
loadSkillProjectModel,
Expand Down Expand Up @@ -83,7 +81,7 @@ function updateSkillProjectWithUserSettings(skillName, projectPath, profile) {
*/
function initializeDeployDelegate(deployerType, projectFolderPath, profile, doDebug, callback) {
// no need to bootstrap if it's self-hosted
if (deployerType === ui.SKIP_DEPLOY_DELEGATE_SELECTION) {
if (!deployerType) {
return callback();
}
// no need to bootstrap as the project is already configured with deployerType
Expand Down
3 changes: 3 additions & 0 deletions lib/commands/new/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function getDeploymentType(deployType, callback) {
pageSize: 30,
filter: input => input.replace(/\n.*/g, '')
}]).then((answer) => {
if (answer.deployDelegate === SKIP_DEPLOY_DELEGATE_SELECTION) {
return callback();
}
callback(null, R.find(R.propEq('OPTION_NAME', answer.deployDelegate))(R.values(deployType)).NAME);
}).catch((error) => {
callback(error);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/new/wizard-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function _getTemplateInfo(cmd, userInput, callback) {
*/
function _newWithOfficialTemplate(language, deploymentType, doDebug, callback) {
let templateIndexUrl;
if (deploymentType === ui.SKIP_DEPLOY_DELEGATE_SELECTION) {
if (!deploymentType) {
templateIndexUrl = CONSTANTS.TEMPLATES.LANGUAGE_MAP[language].TEMPLATE_INDEX;
} else {
templateIndexUrl = DeployDelegate.builtin[deploymentType].templates.language_map[language];
Expand Down
3 changes: 1 addition & 2 deletions test/unit/commands/new/helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('Commands new test - helper test', () => {
const TEST_TEMPLATE_URL = 'value';
const TEST_SKILL_FOLDER_NAME = 'skillFolderName';
const TEST_SKILL_NAME = 'skillName';
const TEST_SKIP_DEPLOY_DELEGATE = 'self-hosted and manage your own hosting';
const TEST_USER_INPUT = {
skillName: 'testName',
projectFolderName: 'projectName',
Expand All @@ -44,7 +43,7 @@ describe('Commands new test - helper test', () => {
it('| ui select deploy delegate pass and selection is opt-out, expect quit process', (done) => {
// setup
// call
helper.initializeDeployDelegate(TEST_SKIP_DEPLOY_DELEGATE, TEST_INFRA_PATH, TEST_PROFILE, TEST_DO_DEBUG, (err, res) => {
helper.initializeDeployDelegate(null, TEST_INFRA_PATH, TEST_PROFILE, TEST_DO_DEBUG, (err, res) => {
// verify
expect(res).equal(undefined);
expect(err).equal(undefined);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/commands/new/ui-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,24 @@ describe('Commands new - UI test', () => {
});
});

it('| self-hosted confirmation entered by user is retrieved correctly', (done) => {
// setup
inquirer.prompt.resolves({ deployDelegate: ui.SKIP_DEPLOY_DELEGATE_SELECTION });
// call
ui.getDeploymentType(TEST_DEPLOYMENT_MAP, (err, response) => {
// verify
validateInquirerConfig(inquirer.prompt.args[0][0][0], {
message: 'Choose a method to host your skill\'s backend resources: ',
type: 'list',
choices: TEST_DEPLOYMENT_CHOICES_WITH_SEP
});
expect(inquirer.prompt.args[0][0][0].filter('a \n \n b')).equal('a ');
expect(err).equal(undefined);
expect(response).equal(undefined);
done();
});
});

it('| get confirmation meets inquirer throws exception', (done) => {
// setup
inquirer.prompt.rejects(new Error(TEST_ERROR));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/commands/new/wizard-helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ We currently only support ".git" url for user's custom template.`;
body: TEST_TEMPLATE_MAP
};
ui.selectSkillCodeLanguage.callsArgWith(0, null, TEST_LANGUAGE_RESPONSE);
ui.getDeploymentType.callsArgWith(1, null, TEST_DEPLOYMENT_MANUAL_TYPE);
ui.getDeploymentType.callsArgWith(1, null);
httpClient.request.callsArgWith(3, null, TEST_HTTP_RESPONSE);
ui.getTargetTemplateName.callsArgWith(1, null, TEST_TEMPLATE_NAME);
ui.getSkillName.callsArgWith(1, TEST_ERROR);
Expand Down

0 comments on commit b1560dc

Please sign in to comment.