Unit tests: - series_service_test.go: test continueSeriesRowToMediaItems conversion with valid fields, null fields, and comprehensive field mapping - series_test.go: test handler initialization and textToString helper Integration tests (series_integration_test.go): - GET /api/series: requires library_id, rejects invalid UUID, returns empty array for empty library, pagination params, limit clamped to 100, response structure validation, special characters in names - GET /api/series/books: requires library_id and name, handles nonexistent series, unauthorized access - Restore Continue Series system collection - Dashboard sections include all 5 collections (including continue-series) Update test helpers: - Add SeriesHandler to setupTestServer router config - Add 5th Continue Series collection to createDefaultCollectionsForUser - Update dashboard integration test for 5 collections
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewSeriesHandler_NilDB(t *testing.T) {
|
|
handler := NewSeriesHandler(nil)
|
|
assert.NotNil(t, handler, "Handler should not be nil even with nil DB")
|
|
assert.NotNil(t, handler.seriesService, "Internal service should be initialized")
|
|
}
|
|
|
|
func TestSeriesHandler_TextToStringConversion(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input pgtype.Text
|
|
expected string
|
|
}{
|
|
{
|
|
name: "valid author text",
|
|
input: pgtype.Text{String: "Brandon Sanderson", Valid: true},
|
|
expected: "Brandon Sanderson",
|
|
},
|
|
{
|
|
name: "empty valid text",
|
|
input: pgtype.Text{String: "", Valid: true},
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "null text returns empty",
|
|
input: pgtype.Text{String: "ignored", Valid: false},
|
|
expected: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := textToString(tt.input)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|