Skip to content

Commit

Permalink
fix(terminal-prompt): remove need for consumer to provide decisions
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jul 30, 2024
1 parent cff87ff commit 7954df4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/prompts/terminal-prompt.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {prompt} from '@form8ion/overridable-prompts';

export default function ({questions, decisions}) {
return prompt(questions, decisions);
export default function (decisions) {
return ({questions}) => prompt(questions, decisions);
}
2 changes: 1 addition & 1 deletion src/prompts/terminal-prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ describe('terminal prompt', () => {
const answers = any.simpleObject();
when(promptWithInquirer).calledWith(questions, decisions).mockResolvedValue(answers);

expect(await prompt({questions, decisions})).toEqual(answers);
expect(await prompt(decisions)({questions})).toEqual(answers);
});
});
4 changes: 2 additions & 2 deletions src/vcs/host/scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {questionNames} from '../../prompts/question-names.js';
import terminalPrompt from '../../prompts/terminal-prompt.js';
import terminalPromptFactory from '../../prompts/terminal-prompt.js';
import promptForVcsHostDetails from './prompt.js';

export default async function (hosts, visibility, decisions, options) {
Expand All @@ -13,7 +13,7 @@ export default async function (hosts, visibility, decisions, options) {
);
const host = lowercasedHosts[chosenHost.toLowerCase()];

if (host) return host.scaffold({...options, owner}, {prompt: terminalPrompt});
if (host) return host.scaffold({...options, owner}, {prompt: terminalPromptFactory(decisions)});

return {vcs: {}};
}
13 changes: 9 additions & 4 deletions src/vcs/host/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import {describe, expect, it, vi} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

import scaffoldVcsHost from './scaffolder.js';
import promptForVcsHostDetails from './prompt.js';
import {questionNames} from '../../prompts/question-names.js';
import terminalPrompt from '../../prompts/terminal-prompt.js';
import terminalPromptFactory from '../../prompts/terminal-prompt.js';
import promptForVcsHostDetails from './prompt.js';
import scaffoldVcsHost from './scaffolder.js';

vi.mock('../../prompts/terminal-prompt.js');
vi.mock('./prompt');

describe('vcs host scaffolder', () => {
Expand All @@ -20,10 +21,14 @@ describe('vcs host scaffolder', () => {
const chosenHostScaffolder = vi.fn();
const hostPlugins = {...any.simpleObject(), [chosenHost.toLowerCase()]: {scaffold: chosenHostScaffolder}};
const owner = any.word;
const terminalPrompt = () => undefined;
when(terminalPromptFactory).calledWith(decisions).mockReturnValue(terminalPrompt);
when(promptForVcsHostDetails)
.calledWith(hostPlugins, visibility, decisions)
.mockResolvedValue({[questionNames.REPO_HOST]: chosenHost, [questionNames.REPO_OWNER]: owner});
when(chosenHostScaffolder).calledWith({...options, owner}, {prompt: terminalPrompt}).mockResolvedValue(results);
when(chosenHostScaffolder)
.calledWith({...options, owner}, {prompt: terminalPrompt})
.mockResolvedValue(results);

expect(await scaffoldVcsHost(hostPlugins, visibility, decisions, options))
.toEqual(results);
Expand Down

0 comments on commit 7954df4

Please sign in to comment.