From b75787e323eb412f0d6410d58bcf0deacee8860d Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 9 Dec 2024 11:51:07 -0600 Subject: [PATCH] chore: fix capitalization of APIv1 --- __tests__/commands/categories/create.test.ts | 26 +-- __tests__/commands/categories/index.test.ts | 10 +- __tests__/commands/changelogs/index.test.ts | 26 +-- __tests__/commands/changelogs/single.test.ts | 24 +-- __tests__/commands/custompages/index.test.ts | 30 ++-- __tests__/commands/custompages/single.test.ts | 28 ++-- __tests__/commands/docs/index.test.ts | 84 +++++----- __tests__/commands/docs/multiple.test.ts | 22 +-- __tests__/commands/docs/prune.test.ts | 22 +-- __tests__/commands/docs/single.test.ts | 58 +++---- __tests__/commands/login.test.ts | 16 +- __tests__/commands/open.test.ts | 4 +- __tests__/commands/openapi/index.test.ts | 148 +++++++++--------- __tests__/commands/versions/create.test.ts | 10 +- __tests__/commands/versions/delete.test.ts | 6 +- __tests__/commands/versions/index.test.ts | 6 +- __tests__/commands/versions/update.test.ts | 20 +-- __tests__/helpers/get-api-mock.ts | 6 +- __tests__/lib/fetch.test.ts | 32 ++-- 19 files changed, 289 insertions(+), 289 deletions(-) diff --git a/__tests__/commands/categories/create.test.ts b/__tests__/commands/categories/create.test.ts index 540d89df4..8b16d38a7 100644 --- a/__tests__/commands/categories/create.test.ts +++ b/__tests__/commands/categories/create.test.ts @@ -2,7 +2,7 @@ import nock from 'nock'; import { describe, beforeAll, afterEach, it, expect } from 'vitest'; import Command from '../../../src/commands/categories/create.js'; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; const key = 'API_KEY'; @@ -33,7 +33,7 @@ describe('rdme categories create', () => { }); it('should create a new category if the title and type do not match and preventDuplicates=true', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .persist() .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) @@ -41,12 +41,12 @@ describe('rdme categories create', () => { 'x-total-count': '1', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/categories') .basicAuth({ user: key }) .reply(201, { title: 'New Category', slug: 'new-category', type: 'guide', id: '123' }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -61,7 +61,7 @@ describe('rdme categories create', () => { }); it('should create a new category if the title matches but the type does not match and preventDuplicates=true', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .persist() .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) @@ -69,12 +69,12 @@ describe('rdme categories create', () => { 'x-total-count': '1', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/categories') .basicAuth({ user: key }) .reply(201, { title: 'Category', slug: 'category', type: 'reference', id: '123' }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -89,12 +89,12 @@ describe('rdme categories create', () => { }); it('should create a new category if the title and type match and preventDuplicates=false', async () => { - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/categories') .basicAuth({ user: key }) .reply(201, { title: 'Category', slug: 'category', type: 'reference', id: '123' }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -108,7 +108,7 @@ describe('rdme categories create', () => { }); it('should not create a new category if the title and type match and preventDuplicates=true', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .persist() .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) @@ -116,7 +116,7 @@ describe('rdme categories create', () => { 'x-total-count': '1', }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -134,7 +134,7 @@ describe('rdme categories create', () => { }); it('should not create a new category if the non case sensitive title and type match and preventDuplicates=true', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .persist() .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) @@ -142,7 +142,7 @@ describe('rdme categories create', () => { 'x-total-count': '1', }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); diff --git a/__tests__/commands/categories/index.test.ts b/__tests__/commands/categories/index.test.ts index c1b14b69e..f3ebb3b54 100644 --- a/__tests__/commands/categories/index.test.ts +++ b/__tests__/commands/categories/index.test.ts @@ -2,7 +2,7 @@ import nock from 'nock'; import { describe, beforeAll, afterEach, it, expect } from 'vitest'; import Command from '../../../src/commands/categories/index.js'; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; const key = 'API_KEY'; @@ -19,7 +19,7 @@ describe('rdme categories', () => { afterEach(() => nock.cleanAll()); it('should return all categories for a single page', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .persist() .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) @@ -27,7 +27,7 @@ describe('rdme categories', () => { 'x-total-count': '1', }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -41,7 +41,7 @@ describe('rdme categories', () => { }); it('should return all categories for multiple pages', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .persist() .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) @@ -54,7 +54,7 @@ describe('rdme categories', () => { 'x-total-count': '21', }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); diff --git a/__tests__/commands/changelogs/index.test.ts b/__tests__/commands/changelogs/index.test.ts index 5e475b546..f9eed6add 100644 --- a/__tests__/commands/changelogs/index.test.ts +++ b/__tests__/commands/changelogs/index.test.ts @@ -8,7 +8,7 @@ import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest'; import Command from '../../../src/commands/changelogs.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; @@ -67,7 +67,7 @@ describe('rdme changelogs', () => { it('should fetch changelog and merge with what is returned', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }) @@ -75,7 +75,7 @@ describe('rdme changelogs', () => { .basicAuth({ user: key }) .reply(200, { slug: anotherDoc.slug, lastUpdatedHash: 'anOldHash' }); - const updateMocks = getAPIV1Mock() + const updateMocks = getAPIv1Mock() .put('/api/v1/changelogs/simple-doc', { body: simpleDoc.doc.content, lastUpdatedHash: simpleDoc.hash, @@ -112,7 +112,7 @@ describe('rdme changelogs', () => { it('should return changelog update info for dry run', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }) @@ -141,7 +141,7 @@ describe('rdme changelogs', () => { it('should not send requests for changelogs that have not changed', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }) @@ -164,7 +164,7 @@ describe('rdme changelogs', () => { it('should adjust "no changes" message if in dry run', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }) @@ -192,7 +192,7 @@ describe('rdme changelogs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/changelogs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -202,7 +202,7 @@ describe('rdme changelogs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); @@ -219,7 +219,7 @@ describe('rdme changelogs', () => { const slug = 'new-doc'; const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/changelogs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -254,7 +254,7 @@ describe('rdme changelogs', () => { const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${folder}/${slug}.md`))); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get(`/api/v1/changelogs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -264,7 +264,7 @@ describe('rdme changelogs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMocks = getAPIV1Mock() + const postMocks = getAPIv1Mock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(400, errorObject); @@ -292,7 +292,7 @@ describe('rdme changelogs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/changelogs/${doc.data.slug}`) .basicAuth({ user: key }) .reply(404, { @@ -302,7 +302,7 @@ describe('rdme changelogs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); diff --git a/__tests__/commands/changelogs/single.test.ts b/__tests__/commands/changelogs/single.test.ts index be6356eca..1d85743a7 100644 --- a/__tests__/commands/changelogs/single.test.ts +++ b/__tests__/commands/changelogs/single.test.ts @@ -8,7 +8,7 @@ import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest'; import Command from '../../../src/commands/changelogs.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; @@ -49,7 +49,7 @@ describe('rdme changelogs (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/changelogs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -59,7 +59,7 @@ describe('rdme changelogs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data }); @@ -76,7 +76,7 @@ describe('rdme changelogs (single)', () => { const slug = 'new-doc'; const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/changelogs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -113,7 +113,7 @@ describe('rdme changelogs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const getMock = getAPIV1Mock().get(`/api/v1/changelogs/${slug}`).basicAuth({ user: key }).reply(500, errorObject); + const getMock = getAPIv1Mock().get(`/api/v1/changelogs/${slug}`).basicAuth({ user: key }).reply(500, errorObject); const filePath = `./__tests__/${fixturesBaseDir}/failure-docs/${slug}.md`; @@ -135,7 +135,7 @@ describe('rdme changelogs (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/changelogs/${doc.data.slug}`) .basicAuth({ user: key }) .reply(404, { @@ -145,7 +145,7 @@ describe('rdme changelogs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); @@ -172,12 +172,12 @@ describe('rdme changelogs (single)', () => { }); it('should fetch changelog and merge with what is returned', () => { - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); - const updateMock = getAPIV1Mock() + const updateMock = getAPIv1Mock() .put('/api/v1/changelogs/simple-doc', { body: simpleDoc.doc.content, lastUpdatedHash: simpleDoc.hash, @@ -202,7 +202,7 @@ describe('rdme changelogs (single)', () => { it('should return changelog update info for dry run', () => { expect.assertions(1); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); @@ -227,7 +227,7 @@ describe('rdme changelogs (single)', () => { it('should not send requests for changelogs that have not changed', () => { expect.assertions(1); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }); @@ -240,7 +240,7 @@ describe('rdme changelogs (single)', () => { }); it('should adjust "no changes" message if in dry run', () => { - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/changelogs/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }); diff --git a/__tests__/commands/custompages/index.test.ts b/__tests__/commands/custompages/index.test.ts index f5bdfe1b0..a0b5061d2 100644 --- a/__tests__/commands/custompages/index.test.ts +++ b/__tests__/commands/custompages/index.test.ts @@ -8,7 +8,7 @@ import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest'; import Command from '../../../src/commands/custompages.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; @@ -67,7 +67,7 @@ describe('rdme custompages', () => { it('should fetch custom page and merge with what is returned', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, htmlmode: false, lastUpdatedHash: 'anOldHash' }) @@ -75,7 +75,7 @@ describe('rdme custompages', () => { .basicAuth({ user: key }) .reply(200, { slug: anotherDoc.slug, htmlmode: false, lastUpdatedHash: 'anOldHash' }); - const updateMocks = getAPIV1Mock() + const updateMocks = getAPIv1Mock() .put('/api/v1/custompages/simple-doc', { body: simpleDoc.doc.content, htmlmode: false, @@ -115,7 +115,7 @@ describe('rdme custompages', () => { it('should return custom page update info for dry run', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }) @@ -144,7 +144,7 @@ describe('rdme custompages', () => { it('should not send requests for custompages that have not changed', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }) @@ -167,7 +167,7 @@ describe('rdme custompages', () => { it('should adjust "no changes" message if in dry run', () => { expect.assertions(1); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }) @@ -195,7 +195,7 @@ describe('rdme custompages', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -205,7 +205,7 @@ describe('rdme custompages', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); @@ -224,7 +224,7 @@ describe('rdme custompages', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -234,7 +234,7 @@ describe('rdme custompages', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/custompages', { slug, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }); @@ -251,7 +251,7 @@ describe('rdme custompages', () => { const slug = 'new-doc'; const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -286,7 +286,7 @@ describe('rdme custompages', () => { const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${folder}/${slug}.md`))); - const getMocks = getAPIV1Mock() + const getMocks = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -296,7 +296,7 @@ describe('rdme custompages', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMocks = getAPIV1Mock() + const postMocks = getAPIv1Mock() .post('/api/v1/custompages', { slug, body: doc.content, htmlmode: false, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(400, errorObject); @@ -324,7 +324,7 @@ describe('rdme custompages', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${doc.data.slug}`) .basicAuth({ user: key }) .reply(404, { @@ -334,7 +334,7 @@ describe('rdme custompages', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); diff --git a/__tests__/commands/custompages/single.test.ts b/__tests__/commands/custompages/single.test.ts index 0bdd184de..e255b3d6c 100644 --- a/__tests__/commands/custompages/single.test.ts +++ b/__tests__/commands/custompages/single.test.ts @@ -8,7 +8,7 @@ import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest'; import Command from '../../../src/commands/custompages.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; @@ -49,7 +49,7 @@ describe('rdme custompages (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -59,7 +59,7 @@ describe('rdme custompages (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data }); @@ -78,7 +78,7 @@ describe('rdme custompages (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -88,7 +88,7 @@ describe('rdme custompages (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/custompages', { slug, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, html: doc.content, htmlmode: true, ...doc.data }); @@ -105,7 +105,7 @@ describe('rdme custompages (single)', () => { const slug = 'new-doc'; const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -142,7 +142,7 @@ describe('rdme custompages (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${slug}`) .basicAuth({ user: key }) .reply(500, errorObject); @@ -167,7 +167,7 @@ describe('rdme custompages (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/custompages/${doc.data.slug}`) .basicAuth({ user: key }) .reply(404, { @@ -177,7 +177,7 @@ describe('rdme custompages (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); @@ -204,12 +204,12 @@ describe('rdme custompages (single)', () => { }); it('should fetch custom page and merge with what is returned', () => { - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); - const updateMock = getAPIV1Mock() + const updateMock = getAPIv1Mock() .put('/api/v1/custompages/simple-doc', { body: simpleDoc.doc.content, htmlmode: false, @@ -236,7 +236,7 @@ describe('rdme custompages (single)', () => { it('should return custom page update info for dry run', () => { expect.assertions(1); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); @@ -261,7 +261,7 @@ describe('rdme custompages (single)', () => { it('should not send requests for custompages that have not changed', () => { expect.assertions(1); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }); @@ -274,7 +274,7 @@ describe('rdme custompages (single)', () => { }); it('should adjust "no changes" message if in dry run', () => { - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get('/api/v1/custompages/simple-doc') .basicAuth({ user: key }) .reply(200, { slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }); diff --git a/__tests__/commands/docs/index.test.ts b/__tests__/commands/docs/index.test.ts index 36bd86ebe..f71d9d12c 100644 --- a/__tests__/commands/docs/index.test.ts +++ b/__tests__/commands/docs/index.test.ts @@ -11,7 +11,7 @@ import { describe, beforeAll, afterAll, beforeEach, afterEach, it, expect, vi, t import Command from '../../../src/commands/docs/index.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import { after, before } from '../../helpers/get-gha-setup.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult, runCommandWithHooks } from '../../helpers/oclif.js'; @@ -39,7 +39,7 @@ describe('rdme docs', () => { }); it('should error if the argument is not a folder', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -52,7 +52,7 @@ describe('rdme docs', () => { }); it('should error if the folder contains no markdown files', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -89,7 +89,7 @@ describe('rdme docs', () => { it('should fetch doc and merge with what is returned', () => { expect.assertions(1); - const getMocks = getAPIV1MockWithVersionHeader(version) + const getMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }) @@ -97,7 +97,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: 'anOldHash' }); - const updateMocks = getAPIV1MockWithVersionHeader(version) + const updateMocks = getAPIv1MockWithVersionHeader(version) .put('/api/v1/docs/simple-doc', { body: simpleDoc.doc.content, lastUpdatedHash: simpleDoc.hash, @@ -117,7 +117,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, body: anotherDoc.doc.content }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -143,7 +143,7 @@ describe('rdme docs', () => { it('should return doc update info for dry run', () => { expect.assertions(1); - const getMocks = getAPIV1MockWithVersionHeader(version) + const getMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }) @@ -151,7 +151,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: 'anOldHash' }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -180,7 +180,7 @@ describe('rdme docs', () => { it('should not send requests for docs that have not changed', () => { expect.assertions(1); - const getMocks = getAPIV1MockWithVersionHeader(version) + const getMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }) @@ -188,7 +188,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: anotherDoc.hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -211,7 +211,7 @@ describe('rdme docs', () => { it('should adjust "no changes" message if in dry run', () => { expect.assertions(1); - const getMocks = getAPIV1MockWithVersionHeader(version) + const getMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }) @@ -219,7 +219,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: anotherDoc.hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -247,7 +247,7 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -257,12 +257,12 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -280,7 +280,7 @@ describe('rdme docs', () => { const slug = 'new-doc'; const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -290,7 +290,7 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -320,7 +320,7 @@ describe('rdme docs', () => { const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${folder}/${slug}.md`))); - const getMocks = getAPIV1MockWithVersionHeader(version) + const getMocks = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -330,12 +330,12 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMocks = getAPIV1MockWithVersionHeader(version) + const postMocks = getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(400, errorObject); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -364,7 +364,7 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/docs/${doc.data.slug}`) .basicAuth({ user: key }) .reply(404, { @@ -374,12 +374,12 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -425,12 +425,12 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const versionsMock = getAPIV1Mock() + const versionsMock = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }, { version: altVersion }]); - const getMock = getAPIV1MockWithVersionHeader(altVersion) + const getMock = getAPIv1MockWithVersionHeader(altVersion) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -440,7 +440,7 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1MockWithVersionHeader(altVersion) + const postMock = getAPIv1MockWithVersionHeader(altVersion) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { _id: id, slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); @@ -469,7 +469,7 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -479,12 +479,12 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -511,7 +511,7 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -521,12 +521,12 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -551,7 +551,7 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -561,12 +561,12 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -600,7 +600,7 @@ describe('rdme docs', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -610,7 +610,7 @@ describe('rdme docs', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock({ + const postMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': @@ -621,7 +621,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -652,7 +652,7 @@ describe('rdme docs', () => { expect.assertions(1); - const getMocks = getAPIV1MockWithVersionHeader(version) + const getMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }) @@ -660,7 +660,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: 'anOldHash' }); - const firstUpdateMock = getAPIV1Mock({ + const firstUpdateMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': @@ -679,7 +679,7 @@ describe('rdme docs', () => { body: simpleDoc.doc.content, }); - const secondUpdateMock = getAPIV1Mock({ + const secondUpdateMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': @@ -694,7 +694,7 @@ describe('rdme docs', () => { .basicAuth({ user: key }) .reply(200, { category, slug: anotherDoc.slug, body: anotherDoc.doc.content }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); diff --git a/__tests__/commands/docs/multiple.test.ts b/__tests__/commands/docs/multiple.test.ts index 2f2d87726..40c0a29de 100644 --- a/__tests__/commands/docs/multiple.test.ts +++ b/__tests__/commands/docs/multiple.test.ts @@ -6,7 +6,7 @@ import nock from 'nock'; import { describe, beforeAll, afterAll, it, expect } from 'vitest'; import Command from '../../../src/commands/docs/index.js'; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; @@ -36,7 +36,7 @@ describe('rdme docs (multiple)', () => { const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); return [ - getAPIV1MockWithVersionHeader(version) + getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -45,7 +45,7 @@ describe('rdme docs (multiple)', () => { suggestion: '...a suggestion to resolve the issue...', help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }), - getAPIV1MockWithVersionHeader(version) + getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) // eslint-disable-next-line no-plusplus @@ -53,7 +53,7 @@ describe('rdme docs (multiple)', () => { ]; }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -83,7 +83,7 @@ describe('rdme docs (multiple)', () => { const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); return [ - getAPIV1MockWithVersionHeader(version) + getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -92,7 +92,7 @@ describe('rdme docs (multiple)', () => { suggestion: '...a suggestion to resolve the issue...', help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }), - getAPIV1MockWithVersionHeader(version) + getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) // eslint-disable-next-line no-plusplus @@ -100,7 +100,7 @@ describe('rdme docs (multiple)', () => { ]; }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -130,7 +130,7 @@ describe('rdme docs (multiple)', () => { const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); return [ - getAPIV1MockWithVersionHeader(version) + getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -139,7 +139,7 @@ describe('rdme docs (multiple)', () => { suggestion: '...a suggestion to resolve the issue...', help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }), - getAPIV1MockWithVersionHeader(version) + getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) // eslint-disable-next-line no-plusplus @@ -147,7 +147,7 @@ describe('rdme docs (multiple)', () => { ]; }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -167,7 +167,7 @@ describe('rdme docs (multiple)', () => { it('should return an error message when it encounters a cycle', async () => { const dir = 'multiple-docs-cycle'; - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); diff --git a/__tests__/commands/docs/prune.test.ts b/__tests__/commands/docs/prune.test.ts index 88b4f0b3d..162e5cb7e 100644 --- a/__tests__/commands/docs/prune.test.ts +++ b/__tests__/commands/docs/prune.test.ts @@ -3,7 +3,7 @@ import prompts from 'prompts'; import { describe, beforeAll, afterAll, it, expect } from 'vitest'; import Command from '../../../src/commands/docs/prune.js'; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult, runCommandWithHooks } from '../../helpers/oclif.js'; const fixturesBaseDir = '__fixtures__/docs'; @@ -27,7 +27,7 @@ describe('rdme docs prune', () => { }); it('should error if the argument is not a folder', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -42,7 +42,7 @@ describe('rdme docs prune', () => { it('should do nothing if the user aborted', async () => { prompts.inject([false]); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -55,12 +55,12 @@ describe('rdme docs prune', () => { }); it('should not ask for user confirmation if `confirm` is set to true', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); - const apiMocks = getAPIV1MockWithVersionHeader(version) + const apiMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) .reply(200, [{ slug: 'category1', type: 'guide' }], { 'x-total-count': '1' }) @@ -82,12 +82,12 @@ describe('rdme docs prune', () => { it('should delete doc if file is missing', async () => { prompts.inject([true]); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); - const apiMocks = getAPIV1MockWithVersionHeader(version) + const apiMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) .reply(200, [{ slug: 'category1', type: 'guide' }], { 'x-total-count': '1' }) @@ -109,12 +109,12 @@ describe('rdme docs prune', () => { it('should delete doc and its child if they are missing', async () => { prompts.inject([true]); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); - const apiMocks = getAPIV1MockWithVersionHeader(version) + const apiMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) .reply(200, [{ slug: 'category1', type: 'guide' }], { 'x-total-count': '1' }) @@ -142,11 +142,11 @@ describe('rdme docs prune', () => { it('should return doc delete info for dry run', async () => { prompts.inject([true]); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); - const apiMocks = getAPIV1MockWithVersionHeader(version) + const apiMocks = getAPIv1MockWithVersionHeader(version) .get('/api/v1/categories?perPage=20&page=1') .basicAuth({ user: key }) .reply(200, [{ slug: 'category1', type: 'guide' }], { 'x-total-count': '1' }) diff --git a/__tests__/commands/docs/single.test.ts b/__tests__/commands/docs/single.test.ts index fa9fac305..007bd28d2 100644 --- a/__tests__/commands/docs/single.test.ts +++ b/__tests__/commands/docs/single.test.ts @@ -8,7 +8,7 @@ import { describe, beforeAll, afterAll, beforeEach, afterEach, it, expect } from import Command from '../../../src/commands/docs/index.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import hashFileContents from '../../helpers/hash-file-contents.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; import { after as afterGHAEnv, before as beforeGHAEnv } from '../../helpers/setup-gha-env.js'; @@ -35,7 +35,7 @@ describe('rdme docs (single)', () => { }); it('should error if the argument is not a Markdown file', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -48,7 +48,7 @@ describe('rdme docs (single)', () => { }); it('should support .markdown files but error if file path cannot be found', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -65,7 +65,7 @@ describe('rdme docs (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -75,12 +75,12 @@ describe('rdme docs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -100,7 +100,7 @@ describe('rdme docs (single)', () => { const slug = 'new-doc'; const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -110,7 +110,7 @@ describe('rdme docs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -128,7 +128,7 @@ describe('rdme docs (single)', () => { }); it('should skip doc if it does not contain any front matter attributes', async () => { - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -152,12 +152,12 @@ describe('rdme docs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(500, errorObject); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -185,7 +185,7 @@ describe('rdme docs (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`))); - const getMock = getAPIV1Mock() + const getMock = getAPIv1Mock() .get(`/api/v1/docs/${doc.data.slug}`) .basicAuth({ user: key }) .reply(404, { @@ -195,12 +195,12 @@ describe('rdme docs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock() + const postMock = getAPIv1Mock() .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -230,12 +230,12 @@ describe('rdme docs (single)', () => { }); it('should fetch doc and merge with what is returned', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); - const updateMock = getAPIV1MockWithVersionHeader(version) + const updateMock = getAPIv1MockWithVersionHeader(version) .put('/api/v1/docs/simple-doc', { body: simpleDoc.doc.content, lastUpdatedHash: simpleDoc.hash, @@ -248,7 +248,7 @@ describe('rdme docs (single)', () => { body: simpleDoc.doc.content, }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -265,12 +265,12 @@ describe('rdme docs (single)', () => { }); it('should return doc update info for dry run', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -297,12 +297,12 @@ describe('rdme docs (single)', () => { }); it('should not send requests for docs that have not changed', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -316,12 +316,12 @@ describe('rdme docs (single)', () => { }); it('should adjust "no changes" message if in dry run', async () => { - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: simpleDoc.hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -355,7 +355,7 @@ describe('rdme docs (single)', () => { const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`))); - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get(`/api/v1/docs/${slug}`) .basicAuth({ user: key }) .reply(404, { @@ -365,7 +365,7 @@ describe('rdme docs (single)', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }); - const postMock = getAPIV1Mock({ + const postMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': @@ -376,7 +376,7 @@ describe('rdme docs (single)', () => { .basicAuth({ user: key }) .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); @@ -400,12 +400,12 @@ describe('rdme docs (single)', () => { hash: hashFileContents(fileContents), }; - const getMock = getAPIV1MockWithVersionHeader(version) + const getMock = getAPIv1MockWithVersionHeader(version) .get('/api/v1/docs/simple-doc') .basicAuth({ user: key }) .reply(200, { category, slug: simpleDoc.slug, lastUpdatedHash: 'anOldHash' }); - const updateMock = getAPIV1Mock({ + const updateMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': @@ -424,7 +424,7 @@ describe('rdme docs (single)', () => { body: simpleDoc.doc.content, }); - const versionMock = getAPIV1Mock() + const versionMock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }); diff --git a/__tests__/commands/login.test.ts b/__tests__/commands/login.test.ts index 24d09c400..e7f559c54 100644 --- a/__tests__/commands/login.test.ts +++ b/__tests__/commands/login.test.ts @@ -5,7 +5,7 @@ import { describe, beforeAll, afterAll, afterEach, it, expect } from 'vitest'; import Command from '../../src/commands/login.js'; import { APIv1Error } from '../../src/lib/apiError.js'; import configStore from '../../src/lib/configstore.js'; -import { getAPIV1Mock } from '../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../helpers/oclif.js'; const apiKey = 'abcdefg'; @@ -39,7 +39,7 @@ describe('rdme login', () => { it('should post to /login on the API', async () => { prompts.inject([email, password, project]); - const mock = getAPIV1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); + const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); await expect(run()).resolves.toBe('Successfully logged in as user@example.com to the subdomain project.'); @@ -53,7 +53,7 @@ describe('rdme login', () => { it('should post to /login on the API if passing in project via opt', async () => { prompts.inject([email, password]); - const mock = getAPIV1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); + const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); await expect(run(['--project', project])).resolves.toBe( 'Successfully logged in as user@example.com to the subdomain project.', @@ -67,7 +67,7 @@ describe('rdme login', () => { }); it('should bypass prompts and post to /login on the API if passing in every opt', async () => { - const mock = getAPIV1Mock().post('/api/v1/login', { email, password, project, token }).reply(200, { apiKey }); + const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project, token }).reply(200, { apiKey }); await expect(run(['--email', email, '--password', password, '--project', project, '--otp', token])).resolves.toBe( 'Successfully logged in as user@example.com to the subdomain project.', @@ -81,7 +81,7 @@ describe('rdme login', () => { }); it('should bypass prompts and post to /login on the API if passing in every opt (no 2FA)', async () => { - const mock = getAPIV1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); + const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(200, { apiKey }); await expect(run(['--email', email, '--password', password, '--project', project])).resolves.toBe( 'Successfully logged in as user@example.com to the subdomain project.', @@ -103,7 +103,7 @@ describe('rdme login', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const mock = getAPIV1Mock().post('/api/v1/login', { email, password, project }).reply(401, errorResponse); + const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(401, errorResponse); await expect(run()).rejects.toStrictEqual(new APIv1Error(errorResponse)); mock.done(); @@ -118,7 +118,7 @@ describe('rdme login', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/login', { email, password, project }) .reply(401, errorResponse) .post('/api/v1/login', { email, password, project, token }) @@ -143,7 +143,7 @@ describe('rdme login', () => { help: 'If you need help, email support@readme.io', }; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/login', { email, password, project: projectThatIsNotYours }) .reply(404, errorResponse); diff --git a/__tests__/commands/open.test.ts b/__tests__/commands/open.test.ts index ccb0a6102..80b961dd3 100644 --- a/__tests__/commands/open.test.ts +++ b/__tests__/commands/open.test.ts @@ -6,7 +6,7 @@ import { describe, afterEach, beforeAll, it, expect } from 'vitest'; import pkg from '../../package.json'; import Command from '../../src/commands/open.js'; import configStore from '../../src/lib/configstore.js'; -import { getAPIV1Mock } from '../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../helpers/oclif.js'; const mockArg = ['--mock']; @@ -53,7 +53,7 @@ describe('rdme open', () => { version, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [versionPayload, { version: '1.0.1' }]); diff --git a/__tests__/commands/openapi/index.test.ts b/__tests__/commands/openapi/index.test.ts index 3a39557c4..d013e4aa7 100644 --- a/__tests__/commands/openapi/index.test.ts +++ b/__tests__/commands/openapi/index.test.ts @@ -11,7 +11,7 @@ import Command from '../../../src/commands/openapi/index.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; import config from '../../../src/lib/config.js'; import petstoreWeird from '../../__fixtures__/petstore-simple-weird-version.json' with { type: 'json' }; -import { getAPIV1Mock, getAPIV1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock, getAPIv1MockWithVersionHeader } from '../../helpers/get-api-mock.js'; import { after, before } from '../../helpers/get-gha-setup.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; import { after as afterGHAEnv, before as beforeGHAEnv } from '../../helpers/setup-gha-env.js'; @@ -88,7 +88,7 @@ describe('rdme openapi', () => { ])('should support uploading a %s definition (format: %s)', async (_, format, specVersion, type) => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: specVersion } }) .get('/api/v1/api-specification') @@ -98,7 +98,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -122,14 +122,14 @@ describe('rdme openapi', () => { prompts.inject(['create']); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) @@ -148,14 +148,14 @@ describe('rdme openapi', () => { it('should create a new spec via `--create` flag', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -171,14 +171,14 @@ describe('rdme openapi', () => { it('should create a new spec via `--create` flag and ignore `--id`', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }]) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -201,7 +201,7 @@ describe('rdme openapi', () => { it('should bundle and upload the expected content', async () => { let requestBody; const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) @@ -216,7 +216,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -237,7 +237,7 @@ describe('rdme openapi', () => { let requestBody; const registryUUID = getRandomRegistryId(); const title = 'some alternative title'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) @@ -252,7 +252,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -274,7 +274,7 @@ describe('rdme openapi', () => { it('should upload the expected content and return raw output', async () => { let requestBody; const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) @@ -289,7 +289,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -314,11 +314,11 @@ describe('rdme openapi', () => { ])('should support updating a %s definition (format: %s)', async (_, format, specVersion, type) => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: specVersion } }); - const putMock = getAPIV1MockWithVersionHeader(version) + const putMock = getAPIv1MockWithVersionHeader(version) .put(`/api/v1/api-specification/${id}`, { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -337,11 +337,11 @@ describe('rdme openapi', () => { expect.assertions(4); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const putMock = getAPIV1MockWithVersionHeader(version) + const putMock = getAPIv1MockWithVersionHeader(version) .put(`/api/v1/api-specification/${id}`, { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -365,14 +365,14 @@ describe('rdme openapi', () => { prompts.inject(['update', 'spec2']); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [ @@ -394,7 +394,7 @@ describe('rdme openapi', () => { it('should discover and upload an API definition if none is provided', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) @@ -406,7 +406,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -430,7 +430,7 @@ describe('rdme openapi', () => { let requestBody; const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) @@ -445,7 +445,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -476,14 +476,14 @@ describe('rdme openapi', () => { prompts.inject(['update', 'spec2']); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [ @@ -504,7 +504,7 @@ describe('rdme openapi', () => { it('should return spec create info for dry run (with working directory)', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) @@ -542,14 +542,14 @@ describe('rdme openapi', () => { it("should update a spec file without prompts if providing `update` and it's the one spec available", async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) @@ -568,7 +568,7 @@ describe('rdme openapi', () => { it('should error if providing `update` and there are multiple specs available', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) @@ -595,7 +595,7 @@ describe('rdme openapi', () => { expect.assertions(5); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) .put('/api/v1/api-specification/spec1', { registryUUID }) @@ -626,7 +626,7 @@ describe('rdme openapi', () => { expect.assertions(2); let requestBody = ''; const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) @@ -638,7 +638,7 @@ describe('rdme openapi', () => { }) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -662,7 +662,7 @@ describe('rdme openapi', () => { const specVersion = '1.2.3'; let requestBody = ''; const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${specVersion}`) .basicAuth({ user: key }) .reply(200, { version: specVersion }) @@ -674,7 +674,7 @@ describe('rdme openapi', () => { }) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(specVersion) + const mockWithHeader = getAPIv1MockWithVersionHeader(specVersion) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -708,7 +708,7 @@ describe('rdme openapi', () => { expect.assertions(2); let requestBody = ''; const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => { requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); requestBody = JSON.parse(requestBody); @@ -752,7 +752,7 @@ describe('rdme openapi', () => { ], }; - const mock = getAPIV1Mock().get(`/api/v1/version/${invalidVersion}`).reply(404, errorObject); + const mock = getAPIv1Mock().get(`/api/v1/version/${invalidVersion}`).reply(404, errorObject); await expect( run([ @@ -773,14 +773,14 @@ describe('rdme openapi', () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version: '1.0.0' }, { version: '1.0.1' }]) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(selectedVersion) + const mockWithHeader = getAPIv1MockWithVersionHeader(selectedVersion) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -820,7 +820,7 @@ describe('rdme openapi', () => { ], }; - const mock = getAPIV1Mock().get('/api/v1/version').reply(401, errorObject); + const mock = getAPIv1Mock().get('/api/v1/version').reply(401, errorObject); await expect( run([require.resolve('@readme/oas-examples/3.1/json/petstore.json'), '--key', 'key']), @@ -857,14 +857,14 @@ describe('rdme openapi', () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -890,11 +890,11 @@ describe('rdme openapi', () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const putMock = getAPIV1MockWithVersionHeader(version) + const putMock = getAPIv1MockWithVersionHeader(version) .put(`/api/v1/api-specification/${id}`, { registryUUID }) .basicAuth({ user: key }) .reply(400, errorObject); @@ -923,7 +923,7 @@ describe('rdme openapi', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) @@ -948,14 +948,14 @@ describe('rdme openapi', () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -974,14 +974,14 @@ describe('rdme openapi', () => { it('should error if API errors (generic upload error)', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -1004,14 +1004,14 @@ describe('rdme openapi', () => { it('should error if API errors (request timeout)', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version: '1.0.0' }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, []) @@ -1059,14 +1059,14 @@ describe('rdme openapi', () => { prompts.inject(['create', true, 'openapi-branch', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) @@ -1095,14 +1095,14 @@ describe('rdme openapi', () => { prompts.inject(['create', 'openapi-branch-github-flag', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) @@ -1131,14 +1131,14 @@ describe('rdme openapi', () => { prompts.inject(['update', 'spec2', true, 'openapi-branch-update-prompt', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [ @@ -1167,14 +1167,14 @@ describe('rdme openapi', () => { prompts.inject([true, 'openapi-branch-create-flag', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${altVersion}`) .basicAuth({ user: key }) .reply(200, { version: altVersion }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(altVersion) + const mockWithHeader = getAPIv1MockWithVersionHeader(altVersion) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -1196,14 +1196,14 @@ describe('rdme openapi', () => { prompts.inject([version, true, 'openapi-branch-create-flag-id-opt', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }, { version: '1.1.0' }]) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -1225,14 +1225,14 @@ describe('rdme openapi', () => { prompts.inject([true, 'openapi-branch-update-flag', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) @@ -1256,7 +1256,7 @@ describe('rdme openapi', () => { prompts.inject([true, 'openapi-branch-workingdirectory', yamlFileName]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) @@ -1268,7 +1268,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1MockWithVersionHeader(version) + const postMock = getAPIv1MockWithVersionHeader(version) .post('/api/v1/api-specification', { registryUUID }) .basicAuth({ user: key }) .reply(201, { _id: 1 }, { location: exampleRefLocation }); @@ -1299,14 +1299,14 @@ describe('rdme openapi', () => { prompts.inject(['create', false]); const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }); - const mockWithHeader = getAPIV1MockWithVersionHeader(version) + const mockWithHeader = getAPIv1MockWithVersionHeader(version) .get('/api/v1/api-specification') .basicAuth({ user: key }) .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) @@ -1343,11 +1343,11 @@ describe('rdme openapi', () => { it('should send proper headers in GitHub Actions CI for local spec file', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID }); - const putMock = getAPIV1Mock({ + const putMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': @@ -1370,13 +1370,13 @@ describe('rdme openapi', () => { const registryUUID = getRandomRegistryId(); const spec = 'https://example.com/openapi.json'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) .reply(201, { registryUUID }); const exampleMock = nock('https://example.com').get('/openapi.json').reply(200, petstoreWeird); - const putMock = getAPIV1Mock({ + const putMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': spec, @@ -1395,7 +1395,7 @@ describe('rdme openapi', () => { it('should contain request header with correct URL with working directory', async () => { const registryUUID = getRandomRegistryId(); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) @@ -1407,7 +1407,7 @@ describe('rdme openapi', () => { .basicAuth({ user: key }) .reply(200, []); - const postMock = getAPIV1Mock({ + const postMock = getAPIv1Mock({ 'x-rdme-ci': 'GitHub Actions (test)', 'x-readme-source': 'cli-gh', 'x-readme-source-url': diff --git a/__tests__/commands/versions/create.test.ts b/__tests__/commands/versions/create.test.ts index 04ea9fac3..014bad9ff 100644 --- a/__tests__/commands/versions/create.test.ts +++ b/__tests__/commands/versions/create.test.ts @@ -4,7 +4,7 @@ import { describe, beforeAll, afterEach, it, expect } from 'vitest'; import Command from '../../../src/commands/versions/create.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; const key = 'API_KEY'; @@ -34,7 +34,7 @@ describe('rdme versions create', () => { prompts.inject([version, false, true, true, false]); const newVersion = '1.0.1'; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }, { version: '1.1.0' }]) @@ -56,7 +56,7 @@ describe('rdme versions create', () => { it('should create a specific version with options', async () => { const newVersion = '1.0.1'; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .post('/api/v1/version', { version: newVersion, codename: 'test', @@ -95,7 +95,7 @@ describe('rdme versions create', () => { it('should create successfully a main version', async () => { const newVersion = '1.0.1'; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .post('/api/v1/version', { version: newVersion, from: '1.0.0', @@ -134,7 +134,7 @@ describe('rdme versions create', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const mockRequest = getAPIV1Mock().post('/api/v1/version').basicAuth({ user: key }).reply(400, errorResponse); + const mockRequest = getAPIv1Mock().post('/api/v1/version').basicAuth({ user: key }).reply(400, errorResponse); await expect(run(['--key', key, version, '--fork', '0.0.5'])).rejects.toStrictEqual(new APIv1Error(errorResponse)); mockRequest.done(); diff --git a/__tests__/commands/versions/delete.test.ts b/__tests__/commands/versions/delete.test.ts index 3dd192506..a82b11efe 100644 --- a/__tests__/commands/versions/delete.test.ts +++ b/__tests__/commands/versions/delete.test.ts @@ -3,7 +3,7 @@ import { describe, beforeAll, afterEach, it, expect } from 'vitest'; import Command from '../../../src/commands/versions/delete.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; const key = 'API_KEY'; @@ -20,7 +20,7 @@ describe('rdme versions delete', () => { afterEach(() => nock.cleanAll()); it('should delete a specific version', async () => { - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .delete(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { removed: true }) @@ -41,7 +41,7 @@ describe('rdme versions delete', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .delete(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(404, errorResponse) diff --git a/__tests__/commands/versions/index.test.ts b/__tests__/commands/versions/index.test.ts index 04f170837..7ba6650d7 100644 --- a/__tests__/commands/versions/index.test.ts +++ b/__tests__/commands/versions/index.test.ts @@ -4,7 +4,7 @@ import nock from 'nock'; import { describe, beforeAll, afterEach, it, expect } from 'vitest'; import Command from '../../../src/commands/versions/index.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; const key = 'API_KEY'; @@ -42,7 +42,7 @@ describe('rdme versions', () => { afterEach(() => nock.cleanAll()); it('should make a request to get a list of existing versions', async () => { - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [versionPayload, version2Payload]); @@ -53,7 +53,7 @@ describe('rdme versions', () => { }); it('should get a specific version object if version flag provided', async () => { - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, versionPayload); diff --git a/__tests__/commands/versions/update.test.ts b/__tests__/commands/versions/update.test.ts index 1dd531cb4..66734d9ab 100644 --- a/__tests__/commands/versions/update.test.ts +++ b/__tests__/commands/versions/update.test.ts @@ -4,7 +4,7 @@ import { describe, beforeAll, afterEach, it, expect } from 'vitest'; import Command from '../../../src/commands/versions/update.js'; import { APIv1Error } from '../../../src/lib/apiError.js'; -import { getAPIV1Mock } from '../../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../../helpers/get-api-mock.js'; import { runCommandAndReturnResult } from '../../helpers/oclif.js'; const key = 'API_KEY'; @@ -32,7 +32,7 @@ describe('rdme versions update', () => { is_hidden: false, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }, { version: versionToChange }]) @@ -60,7 +60,7 @@ describe('rdme versions update', () => { is_hidden: false, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }, { version: versionToChange }]) @@ -84,7 +84,7 @@ describe('rdme versions update', () => { is_beta: true, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get('/api/v1/version') .basicAuth({ user: key }) .reply(200, [{ version }, { version: versionToChange, is_stable: true }]) @@ -112,7 +112,7 @@ describe('rdme versions update', () => { is_stable: false, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${versionToChange}`) .basicAuth({ user: key }) .reply(200, { version: versionToChange }) @@ -158,7 +158,7 @@ describe('rdme versions update', () => { is_stable: false, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${versionToChange}`) .basicAuth({ user: key }) .reply(200, { version: versionToChange }) @@ -205,7 +205,7 @@ describe('rdme versions update', () => { is_stable: false, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${versionToChange}`) .basicAuth({ user: key }) .reply(200, { version: versionToChange }) @@ -247,7 +247,7 @@ describe('rdme versions update', () => { version: versionToChange, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${versionToChange}`) .basicAuth({ user: key }) .reply(200, { version: versionToChange }) @@ -286,7 +286,7 @@ describe('rdme versions update', () => { is_stable: true, }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${versionToChange}`) .basicAuth({ user: key }) .reply(200, { version: versionToChange }) @@ -337,7 +337,7 @@ describe('rdme versions update', () => { help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', }; - const mockRequest = getAPIV1Mock() + const mockRequest = getAPIv1Mock() .get(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(200, { version }) diff --git a/__tests__/helpers/get-api-mock.ts b/__tests__/helpers/get-api-mock.ts index 8afd0c853..c8fc83ff9 100644 --- a/__tests__/helpers/get-api-mock.ts +++ b/__tests__/helpers/get-api-mock.ts @@ -7,7 +7,7 @@ import { getUserAgent } from '../../src/lib/readmeAPIFetch.js'; * Nock wrapper for ReadMe API v1 that adds required * `user-agent` request header so it gets properly picked up by nock. */ -export function getAPIV1Mock(reqHeaders = {}) { +export function getAPIv1Mock(reqHeaders = {}) { return nock(config.host, { reqheaders: { 'User-Agent': getUserAgent(), @@ -16,8 +16,8 @@ export function getAPIV1Mock(reqHeaders = {}) { }); } -export function getAPIV1MockWithVersionHeader(v: string) { - return getAPIV1Mock({ +export function getAPIv1MockWithVersionHeader(v: string) { + return getAPIv1Mock({ 'x-readme-version': v, }); } diff --git a/__tests__/lib/fetch.test.ts b/__tests__/lib/fetch.test.ts index 356e15938..261ec9929 100644 --- a/__tests__/lib/fetch.test.ts +++ b/__tests__/lib/fetch.test.ts @@ -4,7 +4,7 @@ import { describe, beforeEach, afterEach, it, expect, vi, beforeAll, type MockIn import pkg from '../../package.json' with { type: 'json' }; import { cleanAPIv1Headers, handleAPIv1Res, readmeAPIv1Fetch } from '../../src/lib/readmeAPIFetch.js'; -import { getAPIV1Mock } from '../helpers/get-api-mock.js'; +import { getAPIv1Mock } from '../helpers/get-api-mock.js'; import { after, before } from '../helpers/setup-gha-env.js'; describe('#readmeAPIv1Fetch()', () => { @@ -22,7 +22,7 @@ describe('#readmeAPIv1Fetch()', () => { it('should have correct headers for requests in GitHub Action env', async () => { const key = 'API_KEY'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -49,7 +49,7 @@ describe('#readmeAPIv1Fetch()', () => { it('should include source URL header with simple path', async () => { const key = 'API_KEY'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -74,7 +74,7 @@ describe('#readmeAPIv1Fetch()', () => { it('should include source URL header with path that contains weird characters', async () => { const key = 'API_KEY'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -100,7 +100,7 @@ describe('#readmeAPIv1Fetch()', () => { const key = 'API_KEY'; vi.stubEnv('GITHUB_SERVER_URL', undefined); - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -123,7 +123,7 @@ describe('#readmeAPIv1Fetch()', () => { it('should include source URL header with relative path', async () => { const key = 'API_KEY'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -149,7 +149,7 @@ describe('#readmeAPIv1Fetch()', () => { const key = 'API_KEY'; const filePath = 'https://example.com/openapi.json'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -174,7 +174,7 @@ describe('#readmeAPIv1Fetch()', () => { it('should wrap all requests with standard user-agent and source headers', async () => { const key = 'API_KEY'; - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1') .basicAuth({ user: key }) .reply(200, function () { @@ -197,7 +197,7 @@ describe('#readmeAPIv1Fetch()', () => { }); it('should make fetch call if no other request options are provided', async () => { - const mock = getAPIV1Mock() + const mock = getAPIv1Mock() .get('/api/v1/doesnt-need-auth') .reply(200, function () { return this.req.headers; @@ -231,7 +231,7 @@ describe('#readmeAPIv1Fetch()', () => { }); it('should not log anything if no warning header was passed', async () => { - const mock = getAPIV1Mock().get('/api/v1/some-warning').reply(200, undefined, { + const mock = getAPIv1Mock().get('/api/v1/some-warning').reply(200, undefined, { Warning: '', }); @@ -244,7 +244,7 @@ describe('#readmeAPIv1Fetch()', () => { }); it('should surface a single warning header', async () => { - const mock = getAPIV1Mock().get('/api/v1/some-warning').reply(200, undefined, { + const mock = getAPIv1Mock().get('/api/v1/some-warning').reply(200, undefined, { Warning: '199 - "some error"', }); @@ -257,7 +257,7 @@ describe('#readmeAPIv1Fetch()', () => { }); it('should surface multiple warning headers', async () => { - const mock = getAPIV1Mock().get('/api/v1/some-warning').reply(200, undefined, { + const mock = getAPIv1Mock().get('/api/v1/some-warning').reply(200, undefined, { Warning: '199 - "some error" 199 - "another error"', }); @@ -272,7 +272,7 @@ describe('#readmeAPIv1Fetch()', () => { }); it('should surface header content even if parsing fails', async () => { - const mock = getAPIV1Mock().get('/api/v1/some-warning').reply(200, undefined, { + const mock = getAPIv1Mock().get('/api/v1/some-warning').reply(200, undefined, { Warning: 'some garbage error', }); @@ -300,7 +300,7 @@ describe('#readmeAPIv1Fetch()', () => { vi.stubEnv('HTTPS_PROXY', proxy); - const mock = getAPIV1Mock({}).get('/api/v1/proxy').reply(200); + const mock = getAPIv1Mock({}).get('/api/v1/proxy').reply(200); await readmeAPIv1Fetch('/api/v1/proxy'); @@ -312,7 +312,7 @@ describe('#readmeAPIv1Fetch()', () => { vi.stubEnv('https_proxy', proxy); - const mock = getAPIV1Mock({}).get('/api/v1/proxy').reply(200); + const mock = getAPIv1Mock({}).get('/api/v1/proxy').reply(200); await readmeAPIv1Fetch('/api/v1/proxy'); @@ -324,7 +324,7 @@ describe('#readmeAPIv1Fetch()', () => { vi.stubEnv('https_proxy', proxy); - const mock = getAPIV1Mock({}).get('/api/v1/proxy').reply(200); + const mock = getAPIv1Mock({}).get('/api/v1/proxy').reply(200); await readmeAPIv1Fetch('/api/v1/proxy');