Skip to content

Commit e50006a

Browse files
committed
feat(prompt): stopped filtering vcs-host choices by project visibility
will likely provide another way of filtering in the future, but this approach didnt support all visibility options and was not appropriately flexible for expansion BREAKING CHANGE: vcs-host choices are no longer filtered by project visibility
1 parent 3a308af commit e50006a

File tree

6 files changed

+4
-69
lines changed

6 files changed

+4
-69
lines changed

src/prompts/conditionals.js

-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {Separator} from '@form8ion/overridable-prompts';
2-
31
import {questionNames} from './question-names.js';
42

53
export function unlicensedConfirmationShouldBePresented(answers) {
@@ -13,13 +11,3 @@ export function licenseChoicesShouldBePresented(answers) {
1311
export function copyrightInformationShouldBeRequested(answers) {
1412
return !!answers[questionNames.LICENSE];
1513
}
16-
17-
export function filterChoicesByVisibility(choices, visibility) {
18-
return [
19-
...Object.entries(choices)
20-
.filter(([, choice]) => choice[visibility.toLowerCase()])
21-
.reduce((acc, [name]) => ([...acc, name]), []),
22-
new Separator(),
23-
'Other'
24-
];
25-
}

src/prompts/conditionals.test.js

-31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import {Separator} from '@form8ion/overridable-prompts';
2-
31
import {describe, expect, it} from 'vitest';
42
import any from '@travi/any';
53

64
import {questionNames} from './question-names.js';
75
import {
86
copyrightInformationShouldBeRequested,
9-
filterChoicesByVisibility,
107
licenseChoicesShouldBePresented,
118
unlicensedConfirmationShouldBePresented
129
} from './conditionals.js';
@@ -51,32 +48,4 @@ describe('prompt conditionals', () => {
5148
expect(copyrightInformationShouldBeRequested({[questionNames.LICENSE]: undefined})).toBe(false);
5249
});
5350
});
54-
55-
describe('choices by project visibility', () => {
56-
const publicChoices = any.objectWithKeys(
57-
any.listOf(any.word),
58-
{factory: () => ({...any.simpleObject(), public: true})}
59-
);
60-
const privateChoices = any.objectWithKeys(
61-
any.listOf(any.word),
62-
{factory: () => ({...any.simpleObject(), private: true})}
63-
);
64-
const choices = {...publicChoices, ...privateChoices};
65-
66-
it('should list the public hosts for `Public` projects', () => {
67-
expect(filterChoicesByVisibility(choices, 'Public')).toEqual([
68-
...Object.keys(publicChoices),
69-
new Separator(),
70-
'Other'
71-
]);
72-
});
73-
74-
it('should list the private hosts for `Private` projects', () => {
75-
expect(filterChoicesByVisibility(choices, 'Private')).toEqual([
76-
...Object.keys(privateChoices),
77-
new Separator(),
78-
'Other'
79-
]);
80-
});
81-
});
8251
});

src/vcs/host/prompt.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {prompt} from '@form8ion/overridable-prompts';
22

33
import {questionNames} from '../../prompts/question-names.js';
4-
import {filterChoicesByVisibility} from '../../prompts/conditionals.js';
54

65
export default async function (hosts, visibility, decisions) {
76
const answers = await prompt([{
87
name: questionNames.REPO_HOST,
98
type: 'list',
109
message: 'Where will the repository be hosted?',
11-
choices: filterChoicesByVisibility(hosts, visibility)
10+
choices: hosts
1211
}], decisions);
1312
const host = hosts[answers[questionNames.REPO_HOST]];
1413

src/vcs/host/prompt.test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import {afterEach, describe, expect, it, vi} from 'vitest';
44
import any from '@travi/any';
55
import {when} from 'jest-when';
66

7-
import * as conditionals from '../../prompts/conditionals.js';
87
import {questionNames} from '../../prompts/question-names.js';
98
import promptForVcsHostDetails from './prompt.js';
109

1110
vi.mock('@form8ion/overridable-prompts');
1211
vi.mock('../../prompts/conditionals');
1312

1413
describe('vcs host details prompt', () => {
15-
const filteredHostChoices = any.listOf(any.word);
1614
const answers = any.simpleObject();
1715
const decisions = any.simpleObject();
1816

@@ -25,12 +23,11 @@ describe('vcs host details prompt', () => {
2523
const hostNames = [...any.listOf(any.string), host];
2624
const hosts = any.objectWithKeys(hostNames, {factory: () => ({})});
2725
const answersWithHostChoice = {...answers, [questionNames.REPO_HOST]: host};
28-
when(conditionals.filterChoicesByVisibility).calledWith(hosts, null).mockReturnValue(filteredHostChoices);
2926
when(prompts.prompt).calledWith([{
3027
name: questionNames.REPO_HOST,
3128
type: 'list',
3229
message: 'Where will the repository be hosted?',
33-
choices: filteredHostChoices
30+
choices: hosts
3431
}], decisions).mockResolvedValue(answersWithHostChoice);
3532

3633
expect(await promptForVcsHostDetails(hosts, null, decisions)).toEqual(answersWithHostChoice);
@@ -40,12 +37,11 @@ describe('vcs host details prompt', () => {
4037
const hosts = {};
4138
const visibility = any.word();
4239
const answersWithHostChoice = {...answers, [questionNames.REPO_HOST]: 'Other'};
43-
when(conditionals.filterChoicesByVisibility).calledWith(hosts, visibility).mockReturnValue(filteredHostChoices);
4440
when(prompts.prompt).calledWith([{
4541
name: questionNames.REPO_HOST,
4642
type: 'list',
4743
message: 'Where will the repository be hosted?',
48-
choices: filteredHostChoices
44+
choices: hosts
4945
}], decisions).mockResolvedValue(answersWithHostChoice);
5046

5147
expect(await promptForVcsHostDetails(hosts, visibility, decisions)).toEqual(answersWithHostChoice);

src/vcs/host/schema.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import joi from 'joi';
22
import {optionsSchemas} from '@form8ion/core';
33

4-
export default joi.object().pattern(/^/, optionsSchemas.form8ionPlugin.keys({
5-
public: joi.bool(),
6-
private: joi.bool()
7-
}));
4+
export default joi.object().pattern(/^/, optionsSchemas.form8ionPlugin);

src/vcs/host/schema.test.js

-14
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,4 @@ describe('vcs-host plugins schema', () => {
4343
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: () => undefined}}))
4444
.toThrowError(`"${key}.scaffold" must have an arity of 1`);
4545
});
46-
47-
it('should require the `public` property to be a boolean', () => {
48-
expect(() => validateOptions(
49-
vcsHostSchema,
50-
{[key]: {scaffold: foo => foo, prompt: bar => bar, public: any.word()}}
51-
)).toThrowError(`"${key}.public" must be a boolean`);
52-
});
53-
54-
it('should require the `private` property to be a boolean', () => {
55-
expect(() => validateOptions(
56-
vcsHostSchema,
57-
{[key]: {scaffold: foo => foo, prompt: bar => bar, private: any.word()}}
58-
)).toThrowError(`"${key}.private" must be a boolean`);
59-
});
6046
});

0 commit comments

Comments
 (0)