From 3e3c10f6424619dba0166694127a3b07e40c9184 Mon Sep 17 00:00:00 2001 From: Matt Meigs Date: Tue, 31 Oct 2023 15:35:53 -0400 Subject: [PATCH] fix tests --- config/test.json | 1 + src/services/commandExecutor.ts | 6 +----- tests/data/data.ts | 16 ++++++++-------- tests/unit/job/productionJobHandler.test.ts | 2 +- .../unit/repositories/docsetsRepository.test.ts | 8 ++++---- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/config/test.json b/config/test.json index 5a17611ea..ef848324e 100644 --- a/config/test.json +++ b/config/test.json @@ -13,6 +13,7 @@ "fastlyDochubMap": "devfslydochubmap", "entitlementCollection": "entitlements", "docsetsCollection": "docsets", + "featureFlagMonorepoPath": "true", "MONGO_TIMEOUT_S": 1, "JOB_TIMEOUT_S": 10, "RETRY_TIMEOUT_MS": 10, diff --git a/src/services/commandExecutor.ts b/src/services/commandExecutor.ts index 84dfaea5a..9221cfc51 100644 --- a/src/services/commandExecutor.ts +++ b/src/services/commandExecutor.ts @@ -100,11 +100,7 @@ export class GithubCommandExecutor extends ShellCommandExecutor implements IGith branchName: string, newHead: string | null | undefined = null ): Promise { - const pullRepoCommands = [ - `cd repos/${repoDirName}/cloud-docs`, - `git checkout ${branchName}`, - `git pull origin ${branchName}`, - ]; + const pullRepoCommands = [`cd repos/${repoDirName}`, `git checkout ${branchName}`, `git pull origin ${branchName}`]; if (newHead) { pullRepoCommands.push(`git checkout ${newHead} .`); } diff --git a/tests/data/data.ts b/tests/data/data.ts index 595d1d97a..c13b2c5b2 100644 --- a/tests/data/data.ts +++ b/tests/data/data.ts @@ -448,11 +448,13 @@ export class TestDataProvider { return retVal; } - static getAggregationPipeline( - matchConditionField: string, - matchConditionValue: string, - projection?: { [k: string]: number } - ) { + static getAggregationPipeline(matchConditions: { [k: string]: string }, projection?: { [k: string]: number }) { + // Add prefix 'repo' to each field in matchConditions + const formattedMatchConditions = Object.entries(matchConditions).reduce((acc, [key, val]) => { + acc[`repo.${key}`] = val; + return acc; + }, {}); + return [ // Stage 1: Unwind the repos array to create multiple documents for each referenced repo { @@ -469,9 +471,7 @@ export class TestDataProvider { }, // Stage 3: Match documents based on given field { - $match: { - [`repo.${matchConditionField}`]: matchConditionValue, - }, + $match: formattedMatchConditions, }, // Stage 4: Merge/flatten repo into docset { diff --git a/tests/unit/job/productionJobHandler.test.ts b/tests/unit/job/productionJobHandler.test.ts index b6934df7f..bae49d4e5 100644 --- a/tests/unit/job/productionJobHandler.test.ts +++ b/tests/unit/job/productionJobHandler.test.ts @@ -120,7 +120,7 @@ describe('ProductionJobHandler Tests', () => { test('Execute throws error when Downloading makefile repo should update status', async () => { jobHandlerTestHelper.fileSystemServices.saveUrlAsFile .calledWith( - `https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/makefiles/Makefile.${jobHandlerTestHelper.job.payload.repoName}` + `https://raw.githubusercontent.com/mongodb/docs-worker-pool/monorepo-pub-branches/makefiles/Makefile.${jobHandlerTestHelper.job.payload.repoName}` ) .mockImplementation(() => { throw new Error('Error while Downloading makefile'); diff --git a/tests/unit/repositories/docsetsRepository.test.ts b/tests/unit/repositories/docsetsRepository.test.ts index 7a39266e3..1416482df 100644 --- a/tests/unit/repositories/docsetsRepository.test.ts +++ b/tests/unit/repositories/docsetsRepository.test.ts @@ -16,11 +16,11 @@ 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'); + const testPipeline = TestDataProvider.getAggregationPipeline({ repoName: 'test_repo', project: 'test_project' }); dbRepoHelper.collection.aggregate.mockReturnValueOnce({ toArray: () => [], }); - await expect(docsetsRepo.getRepoBranchesByRepoName('test_repo', 'project')).resolves.toEqual({ + await expect(docsetsRepo.getRepoBranchesByRepoName('test_repo', 'test_project')).resolves.toEqual({ status: 'failure', }); expect(dbRepoHelper.collection.aggregate).toBeCalledTimes(1); @@ -28,14 +28,14 @@ describe('Docsets Repository Tests', () => { }); test('getRepoBranchesByRepoName is successfull', async () => { - const testPipeline = TestDataProvider.getAggregationPipeline('repoName', 'test_repo'); + const testPipeline = TestDataProvider.getAggregationPipeline({ repoName: 'test_repo', project: 'test_project' }); dbRepoHelper.collection.aggregate.mockReturnValueOnce({ toArray: () => ({ bucket: {}, url: {}, }), }); - await docsetsRepo.getRepoBranchesByRepoName('test_repo', 'project'); + await docsetsRepo.getRepoBranchesByRepoName('test_repo', 'test_project'); expect(dbRepoHelper.collection.aggregate).toBeCalledTimes(1); expect(dbRepoHelper.collection.aggregate).toBeCalledWith(testPipeline, {}); });