Skip to content

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

Closed

Conversation

mikemando
Copy link

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

  • Provides users with easy access to the highest-rated testimonials.
  • Supports pagination to improve performance and usability.

How Has This Been Tested?

  • Unit Testing:
    • Implemented a test (test_get_top_rated_api) using pytest and unittest.mock.MagicMock.
    • Validates that the API returns a 200 OK response.
    • Confirms the response structure, message, and data.
    • Tests pagination functionality.

Screenshots (if appropriate - Postman, etc):

top_rated_endpoint

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@mikemando mikemando changed the title Feat/top rated testimonials Feat: Top rated testimonials Mar 1, 2025
@mikemando mikemando changed the title Feat: Top rated testimonials Feat: Retrieve top rated testimonials Mar 1, 2025
@mikemando mikemando changed the title Feat: Retrieve top rated testimonials feat: retrieve top rated testimonials Mar 1, 2025
samuelogboye
samuelogboye previously approved these changes Mar 1, 2025
Copy link
Contributor

@samuelogboye samuelogboye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 64 to 66
if page < 1 or per_page < 1:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid pagination parameters")

Copy link
Contributor

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.

Comment on lines 33 to 39
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
Copy link
Contributor

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.

@mikemando mikemando closed this by deleting the head repository Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT]: Fetch Top-Rated Testimonials
2 participants