From 5f86409aea88971bf47b6f17fbb53edb938e97fa Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Mon, 24 Oct 2022 14:15:06 -0700 Subject: [PATCH 1/8] feat(baseCommand): inform user which project they're making changes to --- src/lib/baseCommand.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index 1152ea63b..be11d4e92 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -103,6 +103,12 @@ export default class Command { // eslint-disable-next-line no-param-reassign opts.key = configstore.get('apiKey'); } + + info( + `You're currently making updates to the project: ${configstore.get('project')} on the account ${configstore.get( + 'email' + )}` + ); } if (opts.github && isCI()) { From 1b5ece490310dacf5e372a7462506840ea66f82b Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Mon, 24 Oct 2022 15:50:34 -0700 Subject: [PATCH 2/8] feat(baseCommand): add check to surface notification only if user is logged in --- src/lib/baseCommand.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index be11d4e92..8d33ee966 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -104,11 +104,13 @@ export default class Command { opts.key = configstore.get('apiKey'); } - info( - `You're currently making updates to the project: ${configstore.get('project')} on the account ${configstore.get( - 'email' - )}` - ); + if (configstore.get('email')) { + info( + `You're currently making updates to the project: ${configstore.get( + 'project' + )} on the account ${configstore.get('email')}` + ); + } } if (opts.github && isCI()) { From 816ce0edfa4c3f062d211f6accc2ca5554e71954 Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Thu, 27 Oct 2022 11:24:48 -0700 Subject: [PATCH 3/8] feat(baseCommand): update logic for surfacing project notification --- src/lib/baseCommand.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index 8d33ee966..958b83e52 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -93,6 +93,14 @@ export default class Command { Command.debug(`opts: ${JSON.stringify(opts)}`); if (this.args.some(arg => arg.name === 'key')) { + if (opts.key && configstore.get('apiKey') === opts.key) { + info( + `You're currently making updates to the project: ${configstore.get( + 'project' + )} on the account ${configstore.get('email')}` + ); + } + if (!opts.key) { if (isCI()) { throw new Error('No project API key provided. Please use `--key`.'); @@ -103,14 +111,6 @@ export default class Command { // eslint-disable-next-line no-param-reassign opts.key = configstore.get('apiKey'); } - - if (configstore.get('email')) { - info( - `You're currently making updates to the project: ${configstore.get( - 'project' - )} on the account ${configstore.get('email')}` - ); - } } if (opts.github && isCI()) { From db025248ed270995d48a832d3a1b0496e2105186 Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Thu, 27 Oct 2022 11:25:35 -0700 Subject: [PATCH 4/8] test: add test for surfacing project notifications --- __tests__/index.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index cbfdf38de..fe8373118 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -117,6 +117,41 @@ describe('cli', () => { conf.clear(); }); + describe('project info', () => { + let consoleInfoSpy; + const getCommandOutput = () => { + return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); + }; + + beforeEach(() => { + conf.set('email', 'owlbert@readme.io'); + conf.set('project', 'owlbert'); + conf.set('apiKey', '123456'); + consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(); + }); + + afterEach(() => { + consoleInfoSpy.mockRestore(); + conf.clear(); + }); + + it('should inform a logged in user which project is being updated', async () => { + await expect(cli(['docs'])).rejects.toThrow('No folder provided. Usage `rdme docs [options]`.'); + + expect(getCommandOutput()).toMatch( + "You're currently making updates to the project: owlbert on the account owlbert@readme.io" + ); + }); + + it('should not inform a logged in user when they pass their own key', async () => { + await expect(cli(['docs', '--key=asdf'])).rejects.toThrow( + 'No folder provided. Usage `rdme docs [options]`.' + ); + + expect(getCommandOutput()).toBe(''); + }); + }); + it('should error with `rdme oas` arguments passed in', async () => { await expect(cli(['oas', 'endpoint'])).rejects.toThrow(/.*/); }); From b0e91b049037233b0aac26835bcbb283f557f82d Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Thu, 27 Oct 2022 14:53:43 -0700 Subject: [PATCH 5/8] refactor: copy changes --- __tests__/index.test.ts | 6 ++---- src/lib/baseCommand.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index fe8373118..be7cd4eaf 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -117,7 +117,7 @@ describe('cli', () => { conf.clear(); }); - describe('project info', () => { + describe('logged-in user notifications', () => { let consoleInfoSpy; const getCommandOutput = () => { return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); @@ -138,9 +138,7 @@ describe('cli', () => { it('should inform a logged in user which project is being updated', async () => { await expect(cli(['docs'])).rejects.toThrow('No folder provided. Usage `rdme docs [options]`.'); - expect(getCommandOutput()).toMatch( - "You're currently making updates to the project: owlbert on the account owlbert@readme.io" - ); + expect(getCommandOutput()).toMatch('is currently logged in, using the stored API key for this project:'); }); it('should not inform a logged in user when they pass their own key', async () => { diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index 958b83e52..e15d6e96c 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -3,6 +3,8 @@ import type commands from '../cmds'; import type { CommandLineOptions } from 'command-line-args'; import type { OptionDefinition } from 'command-line-usage'; +import chalk from 'chalk'; + import configstore from './configstore'; import isCI from './isCI'; import { debug, info, warn } from './logger'; @@ -95,9 +97,12 @@ export default class Command { if (this.args.some(arg => arg.name === 'key')) { if (opts.key && configstore.get('apiKey') === opts.key) { info( - `You're currently making updates to the project: ${configstore.get( - 'project' - )} on the account ${configstore.get('email')}` + `🔑 ${configstore.get( + 'email' + )} is currently logged in, using the stored API key for this project: ${chalk.blue( + configstore.get('project') + )}`, + false ); } From f8f8bc7abc867bdcfea3d115eb20e83ab2d0978b Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Thu, 27 Oct 2022 14:54:59 -0700 Subject: [PATCH 6/8] Merge branch 'main' into darren/rm-5582-inform-user-were-using-their-stored From 303723dae65f0c54a25a1f965e298f03246199e4 Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Thu, 27 Oct 2022 15:42:09 -0700 Subject: [PATCH 7/8] refactor: update test to use `openapi` command after `docs:single` refactor --- __tests__/index.test.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index 1ad17d688..b5bd1996c 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -2,6 +2,7 @@ import prompts from 'prompts'; import { version as pkgVersion } from '../package.json'; import cli from '../src'; +import OpenAPICommand from '../src/cmds/openapi'; import conf from '../src/lib/configstore'; import getAPIMock from './helpers/get-api-mock'; @@ -127,15 +128,18 @@ describe('cli', () => { }); it('should inform a logged in user which project is being updated', async () => { - await expect(cli(['docs'])).rejects.toThrow('No folder provided. Usage `rdme docs [options]`.'); + const openapi = new OpenAPICommand(); + const key = '123456'; + + await expect(openapi.run({ key, create: true, update: true })).rejects.toStrictEqual( + new Error('The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!') + ); expect(getCommandOutput()).toMatch('is currently logged in, using the stored API key for this project:'); }); it('should not inform a logged in user when they pass their own key', async () => { - await expect(cli(['docs', '--key=asdf'])).rejects.toThrow( - 'No folder provided. Usage `rdme docs [options]`.' - ); + await expect(cli(['openapi --create --update', '--key=asdf'])).rejects.toThrow('Command not found.'); expect(getCommandOutput()).toBe(''); }); From 5e4ba2298753f4ea6d927a64e51be341fe8df691 Mon Sep 17 00:00:00 2001 From: Darren Yong Date: Thu, 27 Oct 2022 16:34:30 -0700 Subject: [PATCH 8/8] refactor: pass options in correctly --- __tests__/index.test.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index b5bd1996c..546a80b41 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -2,7 +2,6 @@ import prompts from 'prompts'; import { version as pkgVersion } from '../package.json'; import cli from '../src'; -import OpenAPICommand from '../src/cmds/openapi'; import conf from '../src/lib/configstore'; import getAPIMock from './helpers/get-api-mock'; @@ -128,18 +127,17 @@ describe('cli', () => { }); it('should inform a logged in user which project is being updated', async () => { - const openapi = new OpenAPICommand(); - const key = '123456'; - - await expect(openapi.run({ key, create: true, update: true })).rejects.toStrictEqual( - new Error('The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!') + await expect(cli(['openapi', '--create', '--update'])).rejects.toThrow( + 'The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!' ); expect(getCommandOutput()).toMatch('is currently logged in, using the stored API key for this project:'); }); it('should not inform a logged in user when they pass their own key', async () => { - await expect(cli(['openapi --create --update', '--key=asdf'])).rejects.toThrow('Command not found.'); + await expect(cli(['openapi', '--create', '--update', '--key=asdf'])).rejects.toThrow( + 'The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!' + ); expect(getCommandOutput()).toBe(''); });