From 5c0fff626c300edf769b67f97884380d7df2851e Mon Sep 17 00:00:00 2001 From: anabellabuckvar <41971124+anabellabuckvar@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:13:25 -0500 Subject: [PATCH] DOP-3960: use dev endpoint to fetch versioned API spec in staging (#936) * DOP-3999 notify oldgen jobs * DOP-3999 autobuilder php-library * DOP-3999 rollback last change * DOP-3999 undid package-lock changes * DOP-3999 undid package-lock.json changes * DOP-3999 use isNextGen field * DOP-3999 fixed if statement * DOP-3960 dev endpoints for API specs * DOP-3960 updated tests * DOP-3960 save prod changelog data * DOP-3960 save staging data --- .../oas-page-builder/src/services/database.ts | 2 ++ .../oas-page-builder/src/services/pageBuilder.ts | 13 ++++++++++--- .../src/utils/fetchVersionData.ts | 4 ++-- .../tests/unit/services/pageBuilder.test.ts | 16 ++++++++-------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/modules/oas-page-builder/src/services/database.ts b/modules/oas-page-builder/src/services/database.ts index bab7dc988..22515fb82 100644 --- a/modules/oas-page-builder/src/services/database.ts +++ b/modules/oas-page-builder/src/services/database.ts @@ -26,10 +26,12 @@ const getDbName = () => { switch (env) { // Autobuilder's prd env case 'production': + return 'snooty_prod'; case 'dotcomprd': return 'snooty_dotcomprd'; // Autobuilder's pre-prd env case 'staging': + return 'snooty_stage'; case 'dotcomstg': return 'snooty_dotcomstg'; default: diff --git a/modules/oas-page-builder/src/services/pageBuilder.ts b/modules/oas-page-builder/src/services/pageBuilder.ts index a25379be5..9b41bf050 100644 --- a/modules/oas-page-builder/src/services/pageBuilder.ts +++ b/modules/oas-page-builder/src/services/pageBuilder.ts @@ -7,8 +7,15 @@ import { findLastSavedVersionData, saveSuccessfulBuildVersionData } from './data import { VersionData } from './models/OASFile'; import { normalizeUrl } from '../utils/normalizeUrl'; -const OAS_FILE_SERVER = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/'; -const GIT_HASH_URL = 'https://cloud.mongodb.com/version'; +const env = process.env.SNOOTY_ENV ?? ''; + +const OAS_FILE_SERVER = + env === 'dotcomprd' + ? 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/' + : 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/'; + +const GIT_HASH_URL = + env === 'dotcomprd' ? 'https://cloud.mongodb.com/version' : 'https://cloud-dev.mongodb.com/version'; const fetchTextData = async (url: string, errMsg: string) => { const res = await fetch(url); @@ -274,7 +281,7 @@ export const buildOpenAPIPages = async ( if (totalSuccess && sourceType == 'atlas') { try { const gitHash = await fetchGitHash(); - const versions = await fetchVersionData(gitHash); + const versions = await fetchVersionData(gitHash, OAS_FILE_SERVER); await saveSuccessfulBuildVersionData(source, gitHash, versions); } catch (e) { console.error(e); diff --git a/modules/oas-page-builder/src/utils/fetchVersionData.ts b/modules/oas-page-builder/src/utils/fetchVersionData.ts index 5090b133c..953f6d20f 100644 --- a/modules/oas-page-builder/src/utils/fetchVersionData.ts +++ b/modules/oas-page-builder/src/utils/fetchVersionData.ts @@ -1,7 +1,7 @@ import fetch from 'node-fetch'; -export const fetchVersionData = async (gitHash: string) => { - const versionUrl = `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${gitHash}-api-versions.json`; +export const fetchVersionData = async (gitHash: string, serverURL: string) => { + const versionUrl = `${serverURL}${gitHash}-api-versions.json`; const res = await fetch(versionUrl); const { versions } = await res.json(); return versions; diff --git a/modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts b/modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts index dbe57a3af..5d01f1bc8 100644 --- a/modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts +++ b/modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts @@ -95,7 +95,7 @@ describe('pageBuilder', () => { ); // Atlas expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}.json`, getExpectedOutputPath(testOptions.output, testEntries[2][0]), expectedAtlasBuildOptions, undefined @@ -139,7 +139,7 @@ describe('pageBuilder', () => { ); // Atlas expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v1.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v1.json`, getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION), expectedAtlasBuildOptions, undefined @@ -211,14 +211,14 @@ describe('pageBuilder', () => { // Atlas expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`, getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION), expectedAtlasBuildOptions, getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`) ); expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`, getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION), expectedAtlasBuildOptions, getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`) @@ -254,21 +254,21 @@ describe('pageBuilder', () => { await buildOpenAPIPages(testEntries, testOptions); expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${OLDEST_RESOURCE_VERSION}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${OLDEST_RESOURCE_VERSION}.json`, getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, OLDEST_RESOURCE_VERSION), expectedAtlasBuildOptions, getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, OLDEST_RESOURCE_VERSION) ); expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`, getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION), expectedAtlasBuildOptions, getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION) ); expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`, getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION), expectedAtlasBuildOptions, getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION) @@ -283,7 +283,7 @@ describe('pageBuilder', () => { await buildOpenAPIPages(testEntries, testOptions); expect(mockExecute).toBeCalledWith( - `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${LAST_SAVED_GIT_HASH}.json`, + `https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${LAST_SAVED_GIT_HASH}.json`, getExpectedOutputPath(testOptions.output, testEntries[0][0]), expectedAtlasBuildOptions, undefined