Skip to content

Commit 0b2750d

Browse files
authored
chore(prompt): various enhancements and refactors (#576)
* refactor(login): simplify with overrides * test: address TODO * refactor: replace onState with onCancel I was looking through the docs and saw that onState was injected into every question in the question array and would run on every keystroke, and saw that onCancel existed and would look a lot cleaner in our prompt wrapper. * chore: remove `enableTerminalCursor` I'm not sure this is needed? I'm not able to get rid of the cursor anymore 🤔 * refactor: use dynamic key detection * chore: small JS doc * feat(prompts): top-level CI detection
1 parent cc56430 commit 0b2750d

File tree

18 files changed

+68
-36
lines changed

18 files changed

+68
-36
lines changed

__tests__/cmds/login.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,21 @@ describe('rdme login', () => {
103103
mock.done();
104104
});
105105

106-
it.todo('should error if trying to access a project that is not yours');
106+
it('should error if trying to access a project that is not yours', async () => {
107+
const projectThatIsNotYours = 'unauthorized-project';
108+
prompts.inject([email, password, projectThatIsNotYours]);
109+
const errorResponse = {
110+
error: 'PROJECT_NOTFOUND',
111+
message: `The project (${projectThatIsNotYours}) can't be found.`,
112+
suggestion: `The project is referred to as your \`subdomain\` in the dashboard when you're looking for it. If you're sure it exists, maybe you don't have access to it? You can check if it exists here: https://${projectThatIsNotYours}.readme.io.`,
113+
help: 'If you need help, email support@readme.io',
114+
};
115+
116+
const mock = getAPIMock()
117+
.post('/api/v1/login', { email, password, project: projectThatIsNotYours })
118+
.reply(404, errorResponse);
119+
120+
await expect(cmd.run({})).rejects.toStrictEqual(new APIError(errorResponse));
121+
mock.done();
122+
});
107123
});

src/cmds/categories/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class CategoriesCreateCommand extends Command {
5858
}
5959

6060
async run(opts: CommandOptions<Options>) {
61-
super.run(opts, true);
61+
super.run(opts);
6262

6363
const { categoryType, title, key, version, preventDuplicates } = opts;
6464

src/cmds/categories/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default class CategoriesCommand extends Command {
2525
}
2626

2727
async run(opts: CommandOptions<{}>) {
28-
super.run(opts, true);
28+
super.run(opts);
2929

3030
const { key, version } = opts;
3131

src/cmds/changelogs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class ChangelogsCommand extends Command {
4343
}
4444

4545
async run(opts: CommandOptions<Options>) {
46-
super.run(opts, true);
46+
super.run(opts);
4747

4848
const { dryRun, folder, key } = opts;
4949

src/cmds/changelogs/single.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class SingleChangelogCommand extends Command {
4242
}
4343

4444
async run(opts: CommandOptions<Options>) {
45-
super.run(opts, true);
45+
super.run(opts);
4646

4747
const { dryRun, filePath, key } = opts;
4848

src/cmds/custompages/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class CustomPagesCommand extends Command {
4343
}
4444

4545
async run(opts: CommandOptions<Options>) {
46-
super.run(opts, true);
46+
super.run(opts);
4747

4848
const { dryRun, folder, key } = opts;
4949

src/cmds/custompages/single.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class SingleCustomPageCommand extends Command {
4141
}
4242

4343
async run(opts: CommandOptions<Options>) {
44-
super.run(opts, true);
44+
super.run(opts);
4545

4646
const { dryRun, filePath, key } = opts;
4747

src/cmds/docs/edit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class EditDocsCommand extends Command {
4949
}
5050

5151
async run(opts: CommandOptions<Options>): Promise<undefined> {
52-
super.run(opts, true);
52+
super.run(opts);
5353

5454
const { slug, key, version } = opts;
5555

src/cmds/docs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class DocsCommand extends Command {
4545
}
4646

4747
async run(opts: CommandOptions<Options>) {
48-
super.run(opts, true);
48+
super.run(opts);
4949

5050
const { dryRun, folder, key, version } = opts;
5151

src/cmds/docs/single.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class SingleDocCommand extends Command {
4444
}
4545

4646
async run(opts: CommandOptions<Options>) {
47-
super.run(opts, true);
47+
super.run(opts);
4848

4949
const { dryRun, filePath, key, version } = opts;
5050

0 commit comments

Comments
 (0)