diff --git a/cmd/server/tests/dashboard_integration_test.go b/cmd/server/tests/dashboard_integration_test.go index b656b020..b701b2df 100644 --- a/cmd/server/tests/dashboard_integration_test.go +++ b/cmd/server/tests/dashboard_integration_test.go @@ -69,15 +69,16 @@ func (s *DashboardIntegrationTestSuite) TestGetSections_EndToEndFlow() { assert.IsType(s.T(), float64(0), section["priority"], "priority should be number") } - // Verify all system collections exist - assert.Contains(s.T(), sectionMap, "continue-reading") - assert.Contains(s.T(), sectionMap, "recently-added") - assert.Contains(s.T(), sectionMap, "recently-read") - assert.Contains(s.T(), sectionMap, "not-started") - assert.Contains(s.T(), sectionMap, "continue-series") + // Verify all system collections exist (names are the section ids; + // the canonical seed names are Title-case). + assert.Contains(s.T(), sectionMap, "Continue Reading") + assert.Contains(s.T(), sectionMap, "Recently Added") + assert.Contains(s.T(), sectionMap, "Recently Read") + assert.Contains(s.T(), sectionMap, "Not Started") + assert.Contains(s.T(), sectionMap, "Continue Series") // Verify continue-reading is a system collection - continueReading := sectionMap["continue-reading"] + continueReading := sectionMap["Continue Reading"] assert.True(s.T(), continueReading["is_system"].(bool), "continue-reading should be system collection") assert.Equal(s.T(), "📖", continueReading["icon"], "icon should match") } @@ -85,6 +86,8 @@ func (s *DashboardIntegrationTestSuite) TestGetSections_EndToEndFlow() { func (s *DashboardIntegrationTestSuite) TestGetSections_MissingLibraryID() { token := s.setup.Token + // No library_id = the All Libraries view: the endpoint aggregates + // sections across every library (200), it does not 400. req, _ := http.NewRequest("GET", s.setup.Server.URL+"/api/dashboard/sections", nil) req.Header.Set("Authorization", "Bearer "+token) @@ -95,7 +98,14 @@ func (s *DashboardIntegrationTestSuite) TestGetSections_MissingLibraryID() { _ = Body.Close() }(resp.Body) - assert.Equal(s.T(), http.StatusBadRequest, resp.StatusCode) + assert.Equal(s.T(), http.StatusOK, resp.StatusCode) + + var response map[string]interface{} + err = json.NewDecoder(resp.Body).Decode(&response) + require.NoError(s.T(), err) + sections, ok := response["sections"].([]interface{}) + require.True(s.T(), ok, "sections should be an array") + assert.NotEmpty(s.T(), sections, "All Libraries view should aggregate sections") } func (s *DashboardIntegrationTestSuite) TestGetSections_InvalidLibraryID() { diff --git a/cmd/server/tests/test_helpers_test.go b/cmd/server/tests/test_helpers_test.go index 94922263..16ad6365 100644 --- a/cmd/server/tests/test_helpers_test.go +++ b/cmd/server/tests/test_helpers_test.go @@ -275,6 +275,10 @@ func uuidToPGType(u uuid.UUID) pgtype.UUID { // createDefaultCollectionsForUser creates the 4 default system collections for a user func createDefaultCollectionsForUser(t *testing.T, db *database.Queries, userID pgtype.UUID) { ctx := context.Background() + // Canonical Title-case names — the same list the registration seed + // (CreateDefaultCollectionsForUser) and RestoreSystemCollection use. + // A stale kebab-case copy lived here once and duplicated every + // system collection in the shared dev DB. defaultCollections := []struct { Name string Description string @@ -283,11 +287,11 @@ func createDefaultCollectionsForUser(t *testing.T, db *database.Queries, userID QueryType string Priority int32 }{ - {"continue-reading", "Books you're currently reading (0 < progress < 1)", "📖", "#7aa2f7", "continue-reading", 1}, - {"recently-added", "Newly added items to this library", "🆕", "#9ece6a", "recently-added", 2}, - {"recently-read", "Books you've finished (progress >= 1)", "✅", "#e0af68", "recently-read", 3}, - {"not-started", "Books you haven't read yet (progress = 0 or no record)", "📕", "#f7768e", "not-started", 4}, - {"continue-series", "Next book in series you're reading", "📚", "#bb9af7", "continue-series", 5}, + {"Continue Reading", "Books you're currently reading (0 < progress < 1)", "📖", "#7aa2f7", "continue-reading", 1}, + {"Recently Added", "Newly added items to this library", "🆕", "#9ece6a", "recently-added", 2}, + {"Recently Read", "Books you've finished (progress >= 1)", "✅", "#e0af68", "recently-read", 3}, + {"Not Started", "Books you haven't read yet (progress = 0 or no record)", "📕", "#f7768e", "not-started", 4}, + {"Continue Series", "Next book in series you're reading", "📚", "#bb9af7", "continue-series", 5}, } for _, col := range defaultCollections {