diff --git a/content/rest/index.md b/content/rest/index.md index 6b37061511..31231e8f0b 100644 --- a/content/rest/index.md +++ b/content/rest/index.md @@ -84,7 +84,6 @@ children: - /teams - /users - /webhooks -autogenerated: rest --- diff --git a/src/automated-pipelines/tests/rendering.js b/src/automated-pipelines/tests/rendering.js index e8a19dfe4a..a8208241db 100644 --- a/src/automated-pipelines/tests/rendering.js +++ b/src/automated-pipelines/tests/rendering.js @@ -1,45 +1,30 @@ import { jest, test } from '@jest/globals' -import { readdirSync, readFileSync } from 'fs' -import path from 'path' +import { loadPages } from '../../../lib/page-data.js' import { get } from '../../../tests/helpers/e2etest.js' -import { REST_DATA_DIR, REST_SCHEMA_FILENAME } from '../../rest/lib/index.js' -// TODO: Change to test every automated page, not just rest -describe('REST references docs', () => { +describe('autogenerated docs render', () => { jest.setTimeout(3 * 60 * 1000) - test('all category and subcategory REST pages render for free-pro-team', async () => { - // This currently just grabs the 'free-pro-team' schema, but ideally, we'd - // get a list of all categories across all versions. - const freeProTeamVersion = readdirSync(REST_DATA_DIR) - .filter((file) => file.startsWith('fpt')) - .shift() - const freeProTeamSchema = JSON.parse( - readFileSync(path.join(REST_DATA_DIR, freeProTeamVersion, REST_SCHEMA_FILENAME), 'utf8') - ) + test('all automated pages return a 200 success code', async () => { + // Get a list of the autogenerated pages + const pageList = await loadPages(undefined, ['en']) + const autogeneratedPages = pageList.filter((page) => page.autogenerated) - const restCategories = Object.entries(freeProTeamSchema) - .map(([key, subCategory]) => { - const subCategoryKeys = Object.keys(subCategory) - if (subCategoryKeys.length === 1) { - return key - } else { - return subCategoryKeys.map((elem) => `${key}/${elem}`) - } - }) - .flat() + expect.assertions(autogeneratedPages.length) const statusCodes = await Promise.all( - restCategories.map(async (page) => { - const url = `/en/rest/${page}` - const res = await get(url) + autogeneratedPages.map(async (page) => { + const url = page.permalinks[0].href + // Some autogenerated pages can be very slow and might fail. + // So we allow a few retries to avoid false positives. + const res = await get(url, { retries: 3 }) return [url, res.statusCode] }) ) + for (const [url, status] of statusCodes) { expect(status, url).toBe(200) } - expect.assertions(restCategories.length) }) }) diff --git a/tests/unit/openapi-schema.js b/src/rest/tests/openapi-schema.js similarity index 97% rename from tests/unit/openapi-schema.js rename to src/rest/tests/openapi-schema.js index 731dc0e04f..dfd00216f7 100644 --- a/tests/unit/openapi-schema.js +++ b/src/rest/tests/openapi-schema.js @@ -5,8 +5,8 @@ import { describe } from '@jest/globals' import walk from 'walk-sync' import { isPlainObject, difference } from 'lodash-es' -import { isApiVersioned, allVersions } from '../../lib/all-versions.js' -import getRest from '../../src/rest/lib/index.js' +import { isApiVersioned, allVersions } from '../../../lib/all-versions.js' +import getRest from '../lib/index.js' const schemasPath = 'src/rest/data' diff --git a/tests/helpers/e2etest.js b/tests/helpers/e2etest.js index 8ec4618471..6604a6f2d0 100644 --- a/tests/helpers/e2etest.js +++ b/tests/helpers/e2etest.js @@ -11,6 +11,7 @@ export async function get( followAllRedirects: false, headers: {}, responseType: undefined, + retries: 0, } ) { const method = opts.method || 'get' @@ -21,7 +22,7 @@ export async function get( { body: opts.body, headers: opts.headers, - retry: { limit: 0 }, + retry: { limit: opts.retries || 0 }, throwHttpErrors: false, followRedirect: opts.followAllRedirects || opts.followRedirects, responseType: opts.responseType,