From 4e92554383eb4af1427ce8e3f671ccf6ecc5bb60 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Jan 2024 18:32:43 -0600 Subject: [PATCH] test: remove test coverage around `--key` flag these tests were duplicative and felt out of scope of the command tests. will add proper top-level coverage for this! also, couldn't figure out a good way to add coverage in commands without running into weird flakiness and race conditions. --- __tests__/cmds/categories/create.test.ts | 13 ------------- __tests__/cmds/categories/index.test.ts | 13 ------------- __tests__/cmds/changelogs/index.test.ts | 13 ------------- __tests__/cmds/changelogs/single.test.ts | 13 ------------- __tests__/cmds/custompages/index.test.ts | 13 ------------- __tests__/cmds/custompages/single.test.ts | 13 ------------- __tests__/cmds/docs/index.test.ts | 11 ----------- __tests__/cmds/docs/prune.test.ts | 13 ------------- __tests__/cmds/docs/single.test.ts | 11 ----------- __tests__/cmds/openapi/index.test.ts | 9 --------- __tests__/cmds/versions/create.test.ts | 13 ------------- __tests__/cmds/versions/delete.test.ts | 13 ------------- __tests__/cmds/versions/index.test.ts | 13 ------------- __tests__/cmds/versions/update.test.ts | 13 ------------- 14 files changed, 174 deletions(-) diff --git a/__tests__/cmds/categories/create.test.ts b/__tests__/cmds/categories/create.test.ts index 2115d11ce..49fe91577 100644 --- a/__tests__/cmds/categories/create.test.ts +++ b/__tests__/cmds/categories/create.test.ts @@ -25,19 +25,6 @@ describe('rdme categories:create', () => { afterEach(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no title provided', () => { return expect(run(['--key', key])).rejects.toThrow('Missing 1 required arg:\ntitle'); }); diff --git a/__tests__/cmds/categories/index.test.ts b/__tests__/cmds/categories/index.test.ts index b1d43fbf4..118be6301 100644 --- a/__tests__/cmds/categories/index.test.ts +++ b/__tests__/cmds/categories/index.test.ts @@ -25,19 +25,6 @@ describe('rdme categories', () => { afterEach(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should return all categories for a single page', async () => { const getMock = getAPIMockWithVersionHeader(version) .persist() diff --git a/__tests__/cmds/changelogs/index.test.ts b/__tests__/cmds/changelogs/index.test.ts index 41a7ac845..44ba5e66d 100644 --- a/__tests__/cmds/changelogs/index.test.ts +++ b/__tests__/cmds/changelogs/index.test.ts @@ -33,19 +33,6 @@ describe('rdme changelogs', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no path provided', () => { return expect(run(['--key', key])).rejects.toThrow('Missing 1 required arg:\npath'); }); diff --git a/__tests__/cmds/changelogs/single.test.ts b/__tests__/cmds/changelogs/single.test.ts index 0d413778e..161463ec5 100644 --- a/__tests__/cmds/changelogs/single.test.ts +++ b/__tests__/cmds/changelogs/single.test.ts @@ -33,19 +33,6 @@ describe('rdme changelogs (single)', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no file path provided', () => { return expect(run(['--key', key])).rejects.toThrow('Missing 1 required arg:\npath'); }); diff --git a/__tests__/cmds/custompages/index.test.ts b/__tests__/cmds/custompages/index.test.ts index 87f6f2ac9..895573496 100644 --- a/__tests__/cmds/custompages/index.test.ts +++ b/__tests__/cmds/custompages/index.test.ts @@ -33,19 +33,6 @@ describe('rdme custompages', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no path provided', () => { return expect(run(['--key', key])).rejects.toThrow('Missing 1 required arg:\npath'); }); diff --git a/__tests__/cmds/custompages/single.test.ts b/__tests__/cmds/custompages/single.test.ts index c096e38ca..049992548 100644 --- a/__tests__/cmds/custompages/single.test.ts +++ b/__tests__/cmds/custompages/single.test.ts @@ -33,19 +33,6 @@ describe('rdme custompages (single)', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no file path provided', () => { return expect(run(['--key', key])).rejects.toThrow('Missing 1 required arg:\npath'); }); diff --git a/__tests__/cmds/docs/index.test.ts b/__tests__/cmds/docs/index.test.ts index 2dc5b20ea..0105fb2c1 100644 --- a/__tests__/cmds/docs/index.test.ts +++ b/__tests__/cmds/docs/index.test.ts @@ -40,13 +40,6 @@ describe('rdme docs', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - it('should successfully log in user via prompts if API key is not provided', async () => { const email = 'owlbert@readme.io'; const password = 'pass123'; @@ -623,10 +616,6 @@ describe('rdme docs', () => { afterEach(afterGHAEnv); - it('should error in CI if no API key provided', () => { - return expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - }); - it('should sync new docs directory with correct headers', async () => { const slug = 'new-doc'; const id = '1234'; diff --git a/__tests__/cmds/docs/prune.test.ts b/__tests__/cmds/docs/prune.test.ts index 724f5be8e..d9d52685b 100644 --- a/__tests__/cmds/docs/prune.test.ts +++ b/__tests__/cmds/docs/prune.test.ts @@ -28,19 +28,6 @@ describe('rdme docs:prune', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no folder provided', () => { return expect(run(['--key', key, '--version', version])).rejects.rejects.toThrow('Missing 1 required arg:\nfolder'); }); diff --git a/__tests__/cmds/docs/single.test.ts b/__tests__/cmds/docs/single.test.ts index c86c4368f..e07bf23e1 100644 --- a/__tests__/cmds/docs/single.test.ts +++ b/__tests__/cmds/docs/single.test.ts @@ -37,13 +37,6 @@ describe('rdme docs (single)', () => { afterAll(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - it('should error if no file path provided', () => { return expect(run(['--key', key, '--version', version])).rejects.toThrow('Missing 1 required arg:\npath'); }); @@ -357,10 +350,6 @@ describe('rdme docs (single)', () => { afterEach(afterGHAEnv); - it('should error in CI if no API key provided', () => { - return expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - }); - it('should sync new doc with correct headers', async () => { const slug = 'new-doc'; const id = '1234'; diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index b84728ccc..a968d3e43 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -686,11 +686,6 @@ describe('rdme openapi', () => { }); describe('error handling', () => { - it('should prompt for login if no API key provided', () => { - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - return expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - }); - it('should error if `--create` and `--update` flags are passed simultaneously', () => { return expect(run(['--key', key, '--create', '--update'])).rejects.toThrow( '--update=true cannot also be provided when using --create', @@ -1196,10 +1191,6 @@ describe('rdme openapi', () => { afterEach(afterGHAEnv); - it('should error in CI if no API key provided', () => { - return expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - }); - it('should error out if multiple possible spec matches were found', () => { return expect(run(['--key', key, '--version', version])).rejects.toStrictEqual( new Error('Multiple API definitions found in current directory. Please specify file.'), diff --git a/__tests__/cmds/versions/create.test.ts b/__tests__/cmds/versions/create.test.ts index 404346e14..232758ab2 100644 --- a/__tests__/cmds/versions/create.test.ts +++ b/__tests__/cmds/versions/create.test.ts @@ -25,19 +25,6 @@ describe('rdme versions:create', () => { afterEach(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should error if no version provided', () => { return expect(run(['--key', key])).rejects.toThrow('Missing 1 required arg:\nversion'); }); diff --git a/__tests__/cmds/versions/delete.test.ts b/__tests__/cmds/versions/delete.test.ts index a0f0fa794..822542d60 100644 --- a/__tests__/cmds/versions/delete.test.ts +++ b/__tests__/cmds/versions/delete.test.ts @@ -26,19 +26,6 @@ describe('rdme versions:delete', () => { afterEach(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should delete a specific version', async () => { const mockRequest = getAPIMock() .delete(`/api/v1/version/${version}`) diff --git a/__tests__/cmds/versions/index.test.ts b/__tests__/cmds/versions/index.test.ts index 8fd07167b..011ea4d2e 100644 --- a/__tests__/cmds/versions/index.test.ts +++ b/__tests__/cmds/versions/index.test.ts @@ -47,19 +47,6 @@ describe('rdme versions', () => { afterEach(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should make a request to get a list of existing versions', async () => { const mockRequest = getAPIMock() .get('/api/v1/version') diff --git a/__tests__/cmds/versions/update.test.ts b/__tests__/cmds/versions/update.test.ts index 893c7b38e..6bbc051c6 100644 --- a/__tests__/cmds/versions/update.test.ts +++ b/__tests__/cmds/versions/update.test.ts @@ -26,19 +26,6 @@ describe('rdme versions:update', () => { afterEach(() => nock.cleanAll()); - it('should prompt for login if no API key provided', async () => { - const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); - prompts.inject(['this-is-not-an-email', 'password', 'subdomain']); - await expect(run()).rejects.toStrictEqual(new Error('You must provide a valid email address.')); - consoleInfoSpy.mockRestore(); - }); - - it('should error in CI if no API key provided', async () => { - process.env.TEST_RDME_CI = 'true'; - await expect(run()).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); - delete process.env.TEST_RDME_CI; - }); - it('should update a specific version object', async () => { const versionToChange = '1.1.0'; const renamedVersion = '1.1.0-update';