Closed RickDeb2004 closed 11 months ago
@romain-fontugne is this approach good?
@mohamedawnallah do we need to implement these changes?
I don't think we need these changes for multiple reasons:
1) We're already await
on the promise returned from GripApiPlugin.getGripAlarms
before validating the schema result expected schema. validate(result)
.
https://github.com/InternetHealthReport/ihr-website/blob/e94c718ee88cc2415f61be44dad4d43bf02911da/src/plugins/tests/GripApi.test.js#L57
2) I don't think modularity would be helpful because we have only one test case and this gets it complicated in return.
3) I don't think the documentation is very helpful here because the function name indicates cleary what it does so adding more documentation would become redundant.
Mostly, Testing files here follow AAA (Arrange, Act, Assert)
pattern:
https://learn.microsoft.com/en-us/visualstudio/test/unit-test-basics?view=vs-2022#write-your-tests
I don't think we need these changes for multiple reasons:
- We're already
await
on the promise returned fromGripApiPlugin.getGripAlarms
before validating the schema resultexpected schema. validate(result)
. https://github.com/InternetHealthReport/ihr-website/blob/e94c718ee88cc2415f61be44dad4d43bf02911da/src/plugins/tests/GripApi.test.js#L57- I don't think modularity would be helpful because we have only one test case and this gets it complicated in return.
- I don't think the documentation is very helpful here because the function name indicates cleary what it does so adding more documentation would become redundant.
Additional Context
Mostly, Testing files here follow
AAA (Arrange, Act, Assert)
pattern: https://learn.microsoft.com/en-us/visualstudio/test/unit-test-basics?view=vs-2022#write-your-tests
yes I am looking into it.
Synchronous Validation of Asynchronous Code:
Issue: The validation of the result against the expected schema is done synchronously using expectedSchema.validate(result), even though the getGripAlarms function is asynchronous.
Recommendation: Instead of validating synchronously, consider using await expect(result).resolves.toSatisfySchema(expectedSchema) to properly handle the asynchronous nature of the getGripAlarms function.
Refactor getGripAlarms test for better modularity
Extract schema validation logic into a separate function (validateResultSchema) and test data generation logic into a separate function (generateDynamicTestData) to improve code modularity and readability.
"Improve variable naming in getGripAlarms test
Enhance code documentation for getGripAlarms test
Improve Jest assertion in getGripAlarms test
Make validateResultSchema asynchronous for Jest testing.