From c2137b7e3e11b5f5d423fa435b0947462262e607 Mon Sep 17 00:00:00 2001 From: Matt Meigs Date: Thu, 2 Nov 2023 11:51:36 -0400 Subject: [PATCH] PR feedback --- config/default.json | 1 - config/test.json | 1 - src/monorepo/types/aggregation-types.ts | 6 ++++++ src/repositories/docsetsRepository.ts | 3 ++- tests/data/data.ts | 4 ---- tests/unit/repositories/docsetsRepository.test.ts | 5 ++--- 6 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 src/monorepo/types/aggregation-types.ts diff --git a/config/default.json b/config/default.json index 5c2e27394..9b0a73341 100644 --- a/config/default.json +++ b/config/default.json @@ -31,7 +31,6 @@ "gatsbyBaseUrl": "GATSBY_BASE_URL", "previewBuildEnabled": "false", "featureFlagUpdatePages": "false", - "featureFlagMonorepoPath": "false", "featureFlagSearchUI": "false", "gatsbyUseChatbot": "false", "parallel": { diff --git a/config/test.json b/config/test.json index ef848324e..5a17611ea 100644 --- a/config/test.json +++ b/config/test.json @@ -13,7 +13,6 @@ "fastlyDochubMap": "devfslydochubmap", "entitlementCollection": "entitlements", "docsetsCollection": "docsets", - "featureFlagMonorepoPath": "true", "MONGO_TIMEOUT_S": 1, "JOB_TIMEOUT_S": 10, "RETRY_TIMEOUT_MS": 10, diff --git a/src/monorepo/types/aggregation-types.ts b/src/monorepo/types/aggregation-types.ts new file mode 100644 index 000000000..467c9bbf6 --- /dev/null +++ b/src/monorepo/types/aggregation-types.ts @@ -0,0 +1,6 @@ +// Types to narrow matchCondition arguments for Docset aggregations +type DirectoriesKey = 'snooty_toml'; +type RepoBranchesKey = 'project' | 'branches' | 'repoName' | `directories.${DirectoriesKey}`; + +export type MatchCondition = { [key in RepoBranchesKey]+?: string }; +export type Projection = { [key in RepoBranchesKey]+?: number }; diff --git a/src/repositories/docsetsRepository.ts b/src/repositories/docsetsRepository.ts index e21fe926b..166483de1 100644 --- a/src/repositories/docsetsRepository.ts +++ b/src/repositories/docsetsRepository.ts @@ -2,6 +2,7 @@ import { Db } from 'mongodb'; import { BaseRepository } from './baseRepository'; import { ILogger } from '../services/logger'; import { IConfig } from 'config'; +import { MatchCondition, Projection } from '../monorepo/types/aggregation-types'; const docsetsCollectionName = process.env.DOCSETS_COL_NAME || 'docsets'; export class DocsetsRepository extends BaseRepository { @@ -9,7 +10,7 @@ export class DocsetsRepository extends BaseRepository { super(config, logger, 'DocsetsRepository', db.collection(docsetsCollectionName)); } - static getAggregationPipeline(matchConditions: { [k: string]: string }, projection?: { [k: string]: number }) { + static getAggregationPipeline(matchConditions: MatchCondition, projection?: Projection) { const DEFAULT_PROJECTIONS = { _id: 0, repos: 0, diff --git a/tests/data/data.ts b/tests/data/data.ts index f32c92fc1..ec822e2bf 100644 --- a/tests/data/data.ts +++ b/tests/data/data.ts @@ -448,8 +448,4 @@ export class TestDataProvider { } return retVal; } - - static getAggregationPipeline(matchConditions: { [k: string]: string }, projection?: { [k: string]: number }) { - return DocsetsRepository.getAggregationPipeline(matchConditions, projection); - } } diff --git a/tests/unit/repositories/docsetsRepository.test.ts b/tests/unit/repositories/docsetsRepository.test.ts index 1416482df..300ed7196 100644 --- a/tests/unit/repositories/docsetsRepository.test.ts +++ b/tests/unit/repositories/docsetsRepository.test.ts @@ -1,5 +1,4 @@ import { DBRepositoryHelper } from '../../utils/repositoryHelper'; -import { TestDataProvider } from '../../data/data'; import { DocsetsRepository } from '../../../src/repositories/docsetsRepository'; describe('Docsets Repository Tests', () => { @@ -16,7 +15,7 @@ describe('Docsets Repository Tests', () => { describe('Docsets Repository getRepoBranchesByRepoName Tests', () => { test('getRepoBranchesByRepoName returns failure as result is undefined', async () => { - const testPipeline = TestDataProvider.getAggregationPipeline({ repoName: 'test_repo', project: 'test_project' }); + const testPipeline = DocsetsRepository.getAggregationPipeline({ repoName: 'test_repo', project: 'test_project' }); dbRepoHelper.collection.aggregate.mockReturnValueOnce({ toArray: () => [], }); @@ -28,7 +27,7 @@ describe('Docsets Repository Tests', () => { }); test('getRepoBranchesByRepoName is successfull', async () => { - const testPipeline = TestDataProvider.getAggregationPipeline({ repoName: 'test_repo', project: 'test_project' }); + const testPipeline = DocsetsRepository.getAggregationPipeline({ repoName: 'test_repo', project: 'test_project' }); dbRepoHelper.collection.aggregate.mockReturnValueOnce({ toArray: () => ({ bucket: {},