diff --git a/src/app/endpoints/feedback.py b/src/app/endpoints/feedback.py index 2756bdb8..8b28437f 100644 --- a/src/app/endpoints/feedback.py +++ b/src/app/endpoints/feedback.py @@ -30,7 +30,7 @@ feedback_status_lock = threading.Lock() # Response for the feedback endpoint -feedback_response: dict[int | str, dict[str, Any]] = { +feedback_post_response: dict[int | str, dict[str, Any]] = { 200: { "description": "Feedback received and stored", "model": FeedbackResponse, @@ -49,6 +49,32 @@ }, } +feedback_put_response: dict[int | str, dict[str, Any]] = { + 200: { + "description": "Feedback status successfully updated", + "model": FeedbackStatusUpdateResponse, + }, + 400: { + "description": "Missing or invalid credentials provided by client", + "model": UnauthorizedResponse, + }, + 401: { + "description": "Missing or invalid credentials provided by client", + "model": UnauthorizedResponse, + }, + 403: { + "description": "Client does not have permission to access resource", + "model": ForbiddenResponse, + }, +} + +feedback_get_response: dict[int | str, dict[str, Any]] = { + 200: { + "description": "Feedback status successfully retrieved", + "model": StatusResponse, + } +} + def is_feedback_enabled() -> bool: """ @@ -83,7 +109,7 @@ async def assert_feedback_enabled(_request: Request) -> None: ) -@router.post("", responses=feedback_response) +@router.post("", responses=feedback_post_response) @authorize(Action.FEEDBACK) async def feedback_endpoint_handler( feedback_request: FeedbackRequest, @@ -161,7 +187,7 @@ def store_feedback(user_id: str, feedback: dict) -> None: logger.info("Feedback stored successfully at %s", feedback_file_path) -@router.get("/status") +@router.get("/status", responses=feedback_get_response) def feedback_status() -> StatusResponse: """ Handle feedback status requests. @@ -179,7 +205,7 @@ def feedback_status() -> StatusResponse: ) -@router.put("/status") +@router.put("/status", responses=feedback_put_response) @authorize(Action.ADMIN) async def update_feedback_status( feedback_update_request: FeedbackStatusUpdateRequest, diff --git a/src/models/responses.py b/src/models/responses.py index ce529745..1c03bbe8 100644 --- a/src/models/responses.py +++ b/src/models/responses.py @@ -1140,3 +1140,32 @@ def __init__(self, user_id: str, resource: str, resource_id: str): ] } } + + +class InvalidFeedbackStoragePathResponse(AbstractErrorResponse): + """500 Internal Error - Invalid feedback storage path.""" + + def __init__(self, storage_path: str): + """Initialize an InvalidFeedbackStoragePathResponse for feedback storage failures.""" + super().__init__( + detail=DetailModel( + response="Failed to store feedback", + cause=f"Invalid feedback storage path: {storage_path}", + ) + ) + + model_config = { + "json_schema_extra": { + "examples": [ + { + "detail": { + "response": "Failed to store feedback", + "cause": ( + "Invalid feedback storage path: " + "/var/app/data/feedbacks/invalid_path" + ), + } + } + ] + } + } diff --git a/tests/e2e/features/environment.py b/tests/e2e/features/environment.py index 1fb031f0..45f22cbb 100644 --- a/tests/e2e/features/environment.py +++ b/tests/e2e/features/environment.py @@ -145,6 +145,8 @@ def before_feature(context: Context, feature: Feature) -> None: restart_container("lightspeed-stack") if "Feedback" in feature.tags: + context.hostname = os.getenv("E2E_LSC_HOSTNAME", "localhost") + context.port = os.getenv("E2E_LSC_PORT", "8080") context.feedback_conversations = [] @@ -156,7 +158,6 @@ def after_feature(context: Context, feature: Feature) -> None: remove_config_backup(context.default_config_backup) if "Feedback" in feature.tags: - print(context.feedback_conversations) for conversation_id in context.feedback_conversations: url = f"http://{context.hostname}:{context.port}/v1/conversations/{conversation_id}" headers = context.auth_headers if hasattr(context, "auth_headers") else {} diff --git a/tests/e2e/features/feedback.feature b/tests/e2e/features/feedback.feature index 90d172e8..40ef9e08 100644 --- a/tests/e2e/features/feedback.feature +++ b/tests/e2e/features/feedback.feature @@ -260,7 +260,25 @@ Feature: feedback endpoint API tests And The body of the response is the following """ { - "detail": "No Authorization header found" + "detail": { + "cause": "Missing or invalid credentials provided by client", + "response": "Unauthorized" + } + } + """ + + Scenario: Check if update feedback status endpoint is not working when not authorized + Given The system is in default state + And I remove the auth header + When The feedback is enabled + Then The status code of the response is 400 + And The body of the response is the following + """ + { + "detail": { + "cause": "Missing or invalid credentials provided by client", + "response": "Unauthorized" + } } """ diff --git a/tests/e2e/features/steps/feedback.py b/tests/e2e/features/steps/feedback.py index ccd92db3..8cff941a 100644 --- a/tests/e2e/features/steps/feedback.py +++ b/tests/e2e/features/steps/feedback.py @@ -17,7 +17,6 @@ def enable_feedback(context: Context) -> None: assert context is not None payload = {"status": True} access_feedback_put_endpoint(context, payload) - assert context.response.status_code == 200, "Enabling feedback was unsuccessful" @step("The feedback is disabled") # type: ignore @@ -26,7 +25,6 @@ def disable_feedback(context: Context) -> None: assert context is not None payload = {"status": False} access_feedback_put_endpoint(context, payload) - assert context.response.status_code == 200, "Disabling feedback was unsuccessful" @when("I update feedback status with") # type: ignore