Open mirmahathir1 opened 4 months ago
After calling the endpoint
{{url}}/log/donations?startDate=1707237110000&endDate=1717113600000
I got the following response:
{
"status": "OK",
"statusCode": 200,
"message": "Fetched donation count by year and month",
"countByYearMonth": {
"2000": {
"1": 1
},
"2021": {
"1": 1
},
"2024": {
"3": 1,
"4": 1
}
}
}
@mirmahathir1 vai how do I write the schema for this? Shouldn't countByYearMonth
be array? Also for each year, the month is also not fixed this must be array too.
After calling the endpoint
{{url}}/log/donations?startDate=1707237110000&endDate=1717113600000
I got the following response:
{ "status": "OK", "statusCode": 200, "message": "Fetched donation count by year and month", "countByYearMonth": { "2000": { "1": 1 }, "2021": { "1": 1 }, "2024": { "3": 1, "4": 1 } } }
@mirmahathir1 vai how do I write the schema for this? Shouldn't
countByYearMonth
be array? Also for each year, the month is also not fixed this must be array too.
I understand your concern. I wanted to do what you said too because these should have been arrays. But I wanted to make this api endpoint as fast as possible because it would take place on the front page of the UI and essentially uses the entire donations
collection. Therefore, I pushed down the whole implementation of the logic to the database level here:
This essentially generates the response you saw, no other postprocessing occurs in the backend. And accessing the years and months through keys became efficient (in my opinion, I may be wrong though) when I populated the data for the chart here on the frontend:
What I want you to do is,
If you feel like you can't do this with jsonschema
validation, let me know. I'll give a try on this issue and I will assign you new issues
@mirmahathir1 vai I want to use Supertest for testing the apis. Supertest is a popular library with almost 13k star on github.
Here are some references on how you can test your API using Supertest:
Please share your thoughts on this 💭
Go ahead. Write test scripts for this endpoint using supertest. However, make sure to study all the already written tests and make up your mind on how you would maintain a convention to rewrite all the tests (directory structure, cases to be handled etc) incrementally.
TODO: 1) For this issue, just write the test for one single route associated with this issue using supertest by maintaining the convention you want to follow.
2) Modify the npm scripts to make sure that if I run npm run test
(or something similar), all the jest and supertest tests run
I also want to point out that jest, the library already being used, is a very popular library that is in the scene for a long time https://github.com/jestjs/jest
On it 👨💻
🎯 PR Acceptance Criteria
log/donations
endpointlog/donations
endpoint