Skip to content

Commit

Permalink
DOP-3960: use dev endpoint to fetch versioned API spec in staging (#936)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
anabellabuckvar authored Nov 20, 2023
1 parent 37ef215 commit 5c0fff6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 2 additions & 0 deletions modules/oas-page-builder/src/services/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 10 additions & 3 deletions modules/oas-page-builder/src/services/pageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/oas-page-builder/src/utils/fetchVersionData.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 8 additions & 8 deletions modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]}`)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 5c0fff6

Please sign in to comment.