Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with db query safety for finding by name. #20

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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