Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
feat(decisions): enabled providing decisions for the prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jan 21, 2020
1 parent 96f51a3 commit 3937a0d
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 76 deletions.
154 changes: 91 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"travis-lint": "^1.0.0"
},
"dependencies": {
"@form8ion/overridable-prompts": "^1.0.0-alpha.1",
"@octokit/rest": "^16.33.1",
"@travi/cli-messages": "1.0.2",
"git-config": "0.0.7",
"inquirer": "^7.0.0",
"netrc": "^0.1.4",
"write-yaml": "^1.0.0"
}
Expand Down
6 changes: 3 additions & 3 deletions src/prompt.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import gitConfig from 'git-config';
import {prompt as promptWithInquirer} from 'inquirer';
import {prompt as promptWithInquirer} from '@form8ion/overridable-prompts';

export function prompt({account} = {}) {
export function prompt({account, decisions} = {}) {
return promptWithInquirer([
{
name: 'repoOwner',
message: 'What is the id of the repository owner?',
default: account || (gitConfig.sync().github ? gitConfig.sync().github.user : '')
}
]);
], decisions);
}
19 changes: 10 additions & 9 deletions test/unit/prompt-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gitConfig from 'git-config';
import inquirer from 'inquirer';
import * as prompts from '@form8ion/overridable-prompts';
import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
Expand All @@ -9,51 +9,52 @@ suite('prompt', () => {
let sandbox;
const githubUser = any.word();
const answers = any.listOf(any.string);
const decisions = any.simpleObject();

setup(() => {
sandbox = sinon.createSandbox();

sandbox.stub(inquirer, 'prompt');
sandbox.stub(prompts, 'prompt');
sandbox.stub(gitConfig, 'sync');
});

teardown(() => sandbox.restore());

test('that the options are optional', async () => {
gitConfig.sync.returns({github: {user: githubUser}});
inquirer.prompt.resolves(answers);
prompts.prompt.resolves(answers);

assert.equal(await prompt(), answers);
});

test('that the github user is provided as the default owner value if available in the global config', async () => {
gitConfig.sync.returns({github: {user: githubUser}});
inquirer.prompt
prompts.prompt
.withArgs([
{
name: 'repoOwner',
message: 'What is the id of the repository owner?',
default: githubUser
}
])
], decisions)
.resolves(answers);

assert.equal(await prompt({}), answers);
assert.equal(await prompt({decisions}), answers);
});

test('that the github user is not used as the default owner value an override is provided', async () => {
const account = any.word();
gitConfig.sync.returns({github: {user: githubUser}});
inquirer.prompt
prompts.prompt
.withArgs([
{
name: 'repoOwner',
message: 'What is the id of the repository owner?',
default: account
}
])
], decisions)
.resolves(answers);

assert.equal(await prompt({account}), answers);
assert.equal(await prompt({account, decisions}), answers);
});
});

0 comments on commit 3937a0d

Please sign in to comment.