Skip to content

Commit

Permalink
test: reorganize tests so they don't leak console warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Nov 2, 2022
1 parent 6a1c232 commit b320a97
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,17 @@ describe('cli', () => {
await expect(cli([])).resolves.toContain('OpenAPI / Swagger');
});

it('should add stored apiKey to opts', async () => {
expect.assertions(1);
const key = '123456';
const version = '1.0.0';
conf.set('apiKey', key);

const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

await expect(cli(['docs', `--version=${version}`])).rejects.toStrictEqual(
new Error('No path provided. Usage `rdme docs <path> [options]`.')
);

conf.clear();
versionMock.done();
});

describe('logged-in user notifications', () => {
describe('stored API key', () => {
let consoleInfoSpy;
const key = '123456';
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');
conf.set('apiKey', key);
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
});

Expand All @@ -126,6 +111,23 @@ describe('cli', () => {
conf.clear();
});

it('should add stored apiKey to opts', async () => {
expect.assertions(1);
const version = '1.0.0';

const versionMock = getAPIMock()
.get(`/api/v1/version/${version}`)
.basicAuth({ user: key })
.reply(200, { version });

await expect(cli(['docs', `--version=${version}`])).rejects.toStrictEqual(
new Error('No path provided. Usage `rdme docs <path> [options]`.')
);

conf.clear();
versionMock.done();
});

it('should inform a logged in user which project is being updated', async () => {
await expect(cli(['openapi', '--create', '--update'])).rejects.toThrow(
'The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!'
Expand Down

0 comments on commit b320a97

Please sign in to comment.