Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: askx new --template-url -> the language and deployer selection a… #95

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/commands/v2new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ function createNonHostedSkill(cmd, profile, doDebug, userInput, callback) {
return callback(projectErr);
}
Messenger.getInstance().info(`Project for skill "${userInput.skillName}" is successfully created at ${projectFolderPath}\n`);
if (cmd.templateUrl) {
return callback();
}
try {
// 2.load involving M(Model) component (ResourcesConfig & Manifest) from the downloaded skill project with 'default' profile
helper.loadSkillProjectModel(projectFolderPath, 'default');
Expand Down
21 changes: 16 additions & 5 deletions lib/commands/v2new/wizard-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ module.exports = {
*/
function collectUserCreationProjectInfo(cmd, callback) {
const userInput = {};
ui.selectSkillCodeLanguage((languageErr, language) => {
_getSkillCodeLanguage(cmd, (languageErr, language) => {
if (languageErr) {
return callback(languageErr);
}
userInput.language = language;
ui.getDeploymentType(CONSTANTS.DEPLOYER_TYPE, (deploymentErr, deploymentType) => {
_getDeploymentType(cmd, (deploymentErr, deploymentType) => {
if (deploymentErr) {
return callback(deploymentErr);
}
Expand Down Expand Up @@ -62,6 +62,20 @@ function collectUserCreationProjectInfo(cmd, callback) {
});
}

function _getSkillCodeLanguage(cmd, callback) {
if (cmd.templateUrl) {
return callback();
}
ui.selectSkillCodeLanguage((err, res) => callback(err || null, res));
}

function _getDeploymentType(cmd, callback) {
if (cmd.templateUrl) {
return callback();
}
ui.getDeploymentType(CONSTANTS.DEPLOYER_TYPE, (err, res) => callback(err || null, res));
}
Chih-Ying marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get template info for non-hosted skill
* @param {Object} cmd command object
Expand All @@ -73,9 +87,6 @@ function _getTemplateInfo(cmd, userInput, callback) {
if (userInput.language === 'Java') {
return callback('Alexa hosted skills don\'t support Java currently.');
}
if (cmd.templateUrl) {
return callback('No custom template allowed for an Alexa hosted skill.');
}
Chih-Ying marked this conversation as resolved.
Show resolved Hide resolved
process.nextTick(() => {
callback(null, { templateUrl: null, templateName: null });
});
Expand Down
19 changes: 19 additions & 0 deletions test/unit/commands/v2new/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,25 @@ describe('Commands new test - command class test', () => {
});
});

it('| load skill project model succeeds, with custom template, expect no error thrown', (done) => {
// setup
const TEST_CMD_TEMPLATE = {
profile: TEST_PROFILE,
templateUrl: 'templateUrl'
};
const TEST_USER_INPUT = {};
wizardHelper.collectUserCreationProjectInfo.callsArgWith(1, null, TEST_USER_INPUT);
helper.downloadTemplateFromGit.callsArgWith(2, null);
// call
instance.handle(TEST_CMD_TEMPLATE, (err) => {
// verify
expect(err).equal(undefined);
expect(errorStub.callCount).equal(0);
expect(infoStub.callCount).equal(2);
done();
});
});

it('| load skill project model fails, expect error thrown', (done) => {
// setup
const TEST_USER_INPUT = {};
Expand Down
13 changes: 0 additions & 13 deletions test/unit/commands/v2new/wizard-helper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ describe('Commands new test - wizard helper test', () => {
});
});

it('| Hosted skills do not support custom template, expect throw error', (done) => {
// setup
const TEST_HOSTED_ERROR = 'No custom template allowed for an Alexa hosted skill.';
ui.selectSkillCodeLanguage.callsArgWith(0, null, TEST_LANGUAGE_RESPONSE);
ui.getDeploymentType.callsArgWith(1, null, TEST_HOSTED_DEPLOYMENT);
// call
wizardHelper.collectUserCreationProjectInfo(TEST_OPTIONS_WITH_TEMPLATE, (err) => {
// verify
expect(err).equal(TEST_HOSTED_ERROR);
done();
});
});

it('| custom template should not be non-git url, expect throw error', (done) => {
// setup
const TEST_GIT_ERROR = `The provided template url ${TEST_TEMPLATE_URL} is not a supported type. \
Expand Down