Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(baseCommand): inform user which project they're making changes to #643

Merged
merged 10 commits into from
Oct 27, 2022
Merged
35 changes: 35 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,41 @@ describe('cli', () => {
conf.clear();
});

describe('project info', () => {
darrenyong marked this conversation as resolved.
Show resolved Hide resolved
let consoleInfoSpy;
const getCommandOutput = () => {
return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n');
};

beforeEach(() => {
conf.set('email', '[email protected]');
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 <folder> [options]`.');

expect(getCommandOutput()).toMatch(
"You're currently making updates to the project: owlbert on the account [email protected]"
);
});

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 <folder> [options]`.'
);

expect(getCommandOutput()).toBe('');
});
darrenyong marked this conversation as resolved.
Show resolved Hide resolved
});

it('should error with `rdme oas` arguments passed in', async () => {
await expect(cli(['oas', 'endpoint'])).rejects.toThrow(/.*/);
});
Expand Down
8 changes: 8 additions & 0 deletions src/lib/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`
);
darrenyong marked this conversation as resolved.
Show resolved Hide resolved
}

if (!opts.key) {
if (isCI()) {
throw new Error('No project API key provided. Please use `--key`.');
Expand Down