Skip to content

Commit

Permalink
Merge pull request #20 from bcgov/feature/multi-scenario
Browse files Browse the repository at this point in the history
Update with db query safety for finding by name.
  • Loading branch information
brysonjbest authored Jul 10, 2024
2 parents 27a9451 + afa6e15 commit f3de579
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/api/scenarioData/scenarioData.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,13 @@ describe('ScenarioDataService', () => {
it('should return scenarios by filename', async () => {
const goRulesJSONFilename = 'test.json';
const scenarioDataList: ScenarioData[] = [mockScenarioData];
scenarioDataList[0].goRulesJSONFilename = goRulesJSONFilename;
MockScenarioDataModel.find = jest.fn().mockReturnValue({ exec: jest.fn().mockResolvedValue(scenarioDataList) });

const result = await service.getScenariosByFilename(goRulesJSONFilename);

expect(result).toEqual(scenarioDataList);
expect(MockScenarioDataModel.find).toHaveBeenCalledWith({ goRulesJSONFilename });
expect(MockScenarioDataModel.find).toHaveBeenCalledWith({ goRulesJSONFilename: { $eq: goRulesJSONFilename } });
});

it('should throw an error if an error occurs while retrieving scenarios by filename', async () => {
Expand All @@ -287,7 +288,7 @@ describe('ScenarioDataService', () => {
await service.getScenariosByFilename(goRulesJSONFilename);
}).rejects.toThrowError(`Error getting scenarios by filename: ${errorMessage}`);

expect(MockScenarioDataModel.find).toHaveBeenCalledWith({ goRulesJSONFilename });
expect(MockScenarioDataModel.find).toHaveBeenCalledWith({ goRulesJSONFilename: { $eq: goRulesJSONFilename } });
});
});
describe('runDecisionsForScenarios', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/scenarioData/scenarioData.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ScenarioDataService {

async getScenariosByFilename(goRulesJSONFilename: string): Promise<ScenarioData[]> {
try {
return await this.scenarioDataModel.find({ goRulesJSONFilename: goRulesJSONFilename }).exec();
return await this.scenarioDataModel.find({ goRulesJSONFilename: { $eq: goRulesJSONFilename } }).exec();
} catch (error) {
throw new Error(`Error getting scenarios by filename: ${error.message}`);
}
Expand Down

0 comments on commit f3de579

Please sign in to comment.