Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Nov 2, 2023
1 parent e8c1467 commit c2137b7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"gatsbyBaseUrl": "GATSBY_BASE_URL",
"previewBuildEnabled": "false",
"featureFlagUpdatePages": "false",
"featureFlagMonorepoPath": "false",
"featureFlagSearchUI": "false",
"gatsbyUseChatbot": "false",
"parallel": {
Expand Down
1 change: 0 additions & 1 deletion config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"fastlyDochubMap": "devfslydochubmap",
"entitlementCollection": "entitlements",
"docsetsCollection": "docsets",
"featureFlagMonorepoPath": "true",
"MONGO_TIMEOUT_S": 1,
"JOB_TIMEOUT_S": 10,
"RETRY_TIMEOUT_MS": 10,
Expand Down
6 changes: 6 additions & 0 deletions src/monorepo/types/aggregation-types.ts
Original file line number Diff line number Diff line change
@@ -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 };
3 changes: 2 additions & 1 deletion src/repositories/docsetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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 {
constructor(db: Db, config: IConfig, logger: ILogger) {
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,
Expand Down
4 changes: 0 additions & 4 deletions tests/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,4 @@ export class TestDataProvider {
}
return retVal;
}

static getAggregationPipeline(matchConditions: { [k: string]: string }, projection?: { [k: string]: number }) {
return DocsetsRepository.getAggregationPipeline(matchConditions, projection);
}
}
5 changes: 2 additions & 3 deletions tests/unit/repositories/docsetsRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DBRepositoryHelper } from '../../utils/repositoryHelper';
import { TestDataProvider } from '../../data/data';
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';

describe('Docsets Repository Tests', () => {
Expand All @@ -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: () => [],
});
Expand All @@ -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: {},
Expand Down

0 comments on commit c2137b7

Please sign in to comment.