-
Notifications
You must be signed in to change notification settings - Fork 214
feat: retrieve top rated testimonials #1171
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
api/v1/services/testimonial.py
Outdated
if page < 1 or per_page < 1: | ||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid pagination parameters") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of manually checking page < 1 or per_page < 1, FastAPI's Query parameters already enforce the constraints (ge=1), so this check is redundant.
db_session_mock.query().order_by().offset().limit().all.return_value = [mock_testimonial] | ||
|
||
response = client.get("/api/v1/testimonials/top-rated", params={"page": 1, "per_page": 1}) | ||
|
||
assert response.status_code == 200 | ||
assert response.json()["message"] == "Top-rated testimonials retrieved successfully." | ||
assert len(response.json()["data"]) == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for edge cases like
No testimonials in the database, Invalid page or per_page parameters, Database failure scenario.
Description
This PR introduces a new API endpoint
/api/v1/testimonials/top-rated
that allows users to retrieve testimonials sorted by rating. It also includes a unit test to ensure the API works as expected.
Related Issue (Link to issue ticket)
closes #1142
Motivation and Context
How Has This Been Tested?
test_get_top_rated_api
) usingpytest
andunittest.mock.MagicMock
.
Screenshots (if appropriate - Postman, etc):
Types of changes
Checklist: