From f0b60f3f139ad69e23174e13d34db05e6a954c3b Mon Sep 17 00:00:00 2001 From: oabrivard Date: Tue, 31 Mar 2026 11:25:10 +0200 Subject: [PATCH] fix: return 204 No Content from preferred sources endpoint The API client expects empty responses to use 204, not 200. Returning 200 with no body caused JSON parse error in the frontend. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/src/handlers/sources.rs | 2 +- backend/tests/api_sources_preferred_test.rs | 4 ++-- backend/tests/pipeline_test.rs | 2 +- e2e/tests/sources.spec.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/handlers/sources.rs b/backend/src/handlers/sources.rs index 0c276f7..67e38ab 100644 --- a/backend/src/handlers/sources.rs +++ b/backend/src/handlers/sources.rs @@ -324,5 +324,5 @@ pub async fn update_preferred( } db::sources::update_preferred(&state.pool, auth_user.id, &body.source_ids, body.theme_id).await?; - Ok(StatusCode::OK) + Ok(StatusCode::NO_CONTENT) } diff --git a/backend/tests/api_sources_preferred_test.rs b/backend/tests/api_sources_preferred_test.rs index e1aa8e4..b2f9f62 100644 --- a/backend/tests/api_sources_preferred_test.rs +++ b/backend/tests/api_sources_preferred_test.rs @@ -62,7 +62,7 @@ async fn update_preferred_sets_sources() { let (pref_status, _) = app .put_with_session("/api/v1/sources/preferred", &pref_body, &session) .await; - assert_eq!(pref_status, StatusCode::OK); + assert_eq!(pref_status, StatusCode::NO_CONTENT); // GET /sources → verify preferred flags let (list_status, list_body) = app @@ -132,7 +132,7 @@ async fn update_preferred_clears_all_when_empty() { let (pref_status, _) = app .put_with_session("/api/v1/sources/preferred", &pref_body, &session) .await; - assert_eq!(pref_status, StatusCode::OK); + assert_eq!(pref_status, StatusCode::NO_CONTENT); // Clear all preferred let clear_body = serde_json::json!({ diff --git a/backend/tests/pipeline_test.rs b/backend/tests/pipeline_test.rs index 8bf552e..a6ed0a1 100644 --- a/backend/tests/pipeline_test.rs +++ b/backend/tests/pipeline_test.rs @@ -638,7 +638,7 @@ async fn preferred_sources_processed_first() { let (pref_status, _) = app .put_with_session("/api/v1/sources/preferred", &pref_body, &session) .await; - assert_eq!(pref_status.as_u16(), 200, "Setting preferred sources should succeed"); + assert_eq!(pref_status.as_u16(), 204, "Setting preferred sources should succeed"); // Run the pipeline let mock_provider = MockLlmProvider::new() diff --git a/e2e/tests/sources.spec.ts b/e2e/tests/sources.spec.ts index 6ac050f..3f4f01f 100644 --- a/e2e/tests/sources.spec.ts +++ b/e2e/tests/sources.spec.ts @@ -132,7 +132,7 @@ test.describe('Sources management', () => { }); return { status: resp.status }; }, { ids: [sourceId2], tid: themeId }); - expect(prefResp.status).toBe(200); + expect(prefResp.status).toBe(204); // Step 9: Verify source is now preferred const listResp3 = await page.evaluate(async (tid: string) => {