Skip to content

Commit

Permalink
feat(prompt): stopped filtering vcs-host choices by project visibility
Browse files Browse the repository at this point in the history
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
  • Loading branch information
travi committed Aug 3, 2024
1 parent 3a308af commit e50006a
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 69 deletions.
12 changes: 0 additions & 12 deletions src/prompts/conditionals.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {Separator} from '@form8ion/overridable-prompts';

import {questionNames} from './question-names.js';

export function unlicensedConfirmationShouldBePresented(answers) {
Expand All @@ -13,13 +11,3 @@ export function licenseChoicesShouldBePresented(answers) {
export function copyrightInformationShouldBeRequested(answers) {
return !!answers[questionNames.LICENSE];
}

export function filterChoicesByVisibility(choices, visibility) {
return [
...Object.entries(choices)
.filter(([, choice]) => choice[visibility.toLowerCase()])
.reduce((acc, [name]) => ([...acc, name]), []),
new Separator(),
'Other'
];
}
31 changes: 0 additions & 31 deletions src/prompts/conditionals.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {Separator} from '@form8ion/overridable-prompts';

import {describe, expect, it} from 'vitest';
import any from '@travi/any';

import {questionNames} from './question-names.js';
import {
copyrightInformationShouldBeRequested,
filterChoicesByVisibility,
licenseChoicesShouldBePresented,
unlicensedConfirmationShouldBePresented
} from './conditionals.js';
Expand Down Expand Up @@ -51,32 +48,4 @@ describe('prompt conditionals', () => {
expect(copyrightInformationShouldBeRequested({[questionNames.LICENSE]: undefined})).toBe(false);
});
});

describe('choices by project visibility', () => {
const publicChoices = any.objectWithKeys(
any.listOf(any.word),
{factory: () => ({...any.simpleObject(), public: true})}
);
const privateChoices = any.objectWithKeys(
any.listOf(any.word),
{factory: () => ({...any.simpleObject(), private: true})}
);
const choices = {...publicChoices, ...privateChoices};

it('should list the public hosts for `Public` projects', () => {
expect(filterChoicesByVisibility(choices, 'Public')).toEqual([
...Object.keys(publicChoices),
new Separator(),
'Other'
]);
});

it('should list the private hosts for `Private` projects', () => {
expect(filterChoicesByVisibility(choices, 'Private')).toEqual([
...Object.keys(privateChoices),
new Separator(),
'Other'
]);
});
});
});
3 changes: 1 addition & 2 deletions src/vcs/host/prompt.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {prompt} from '@form8ion/overridable-prompts';

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

export default async function (hosts, visibility, decisions) {
const answers = await prompt([{
name: questionNames.REPO_HOST,
type: 'list',
message: 'Where will the repository be hosted?',
choices: filterChoicesByVisibility(hosts, visibility)
choices: hosts
}], decisions);
const host = hosts[answers[questionNames.REPO_HOST]];

Expand Down
8 changes: 2 additions & 6 deletions src/vcs/host/prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import {afterEach, describe, expect, it, vi} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

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

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

describe('vcs host details prompt', () => {
const filteredHostChoices = any.listOf(any.word);
const answers = any.simpleObject();
const decisions = any.simpleObject();

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

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

expect(await promptForVcsHostDetails(hosts, visibility, decisions)).toEqual(answersWithHostChoice);
Expand Down
5 changes: 1 addition & 4 deletions src/vcs/host/schema.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import joi from 'joi';
import {optionsSchemas} from '@form8ion/core';

export default joi.object().pattern(/^/, optionsSchemas.form8ionPlugin.keys({
public: joi.bool(),
private: joi.bool()
}));
export default joi.object().pattern(/^/, optionsSchemas.form8ionPlugin);
14 changes: 0 additions & 14 deletions src/vcs/host/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,4 @@ describe('vcs-host plugins schema', () => {
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: () => undefined}}))
.toThrowError(`"${key}.scaffold" must have an arity of 1`);
});

it('should require the `public` property to be a boolean', () => {
expect(() => validateOptions(
vcsHostSchema,
{[key]: {scaffold: foo => foo, prompt: bar => bar, public: any.word()}}
)).toThrowError(`"${key}.public" must be a boolean`);
});

it('should require the `private` property to be a boolean', () => {
expect(() => validateOptions(
vcsHostSchema,
{[key]: {scaffold: foo => foo, prompt: bar => bar, private: any.word()}}
)).toThrowError(`"${key}.private" must be a boolean`);
});
});

0 comments on commit e50006a

Please sign in to comment.