61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package catalog
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestHistorySourceCanUseOptimizedPageQuery(t *testing.T) {
|
|
req := CatalogRequest{
|
|
Source: CatalogSourceHistory,
|
|
UseSourceOrder: true,
|
|
Query: QueryDefinition{},
|
|
}
|
|
|
|
if !historySourceCanUseOptimizedPageQuery(req) {
|
|
t.Fatal("expected bare history source-order request to use optimized page query")
|
|
}
|
|
|
|
req.SearchQuery = "house"
|
|
if historySourceCanUseOptimizedPageQuery(req) {
|
|
t.Fatal("expected search history request to fall back to generic resolver path")
|
|
}
|
|
}
|
|
|
|
func TestBuildHistoryDisplayBaseQueryIncludesSnapshotAndLibraryAccess(t *testing.T) {
|
|
snapshot := time.Date(2026, time.April, 6, 12, 0, 0, 0, time.UTC)
|
|
query, args := buildHistoryDisplayBaseQuery(AccessFilter{
|
|
UserID: 7,
|
|
ProfileID: "profile-1",
|
|
AllowedLibraryIDs: []int{11, 12},
|
|
DisabledLibraryIDs: []int{99},
|
|
MaxContentRating: "PG-13",
|
|
}, &snapshot)
|
|
|
|
expectedFragments := []string{
|
|
"h.user_id = $1",
|
|
"h.profile_id = $2",
|
|
"h.watched_at <= $3",
|
|
"media_item_libraries mil",
|
|
"media_folder_id = ANY($4)",
|
|
"media_item_libraries mil_disabled",
|
|
"media_folder_id = ANY($5)",
|
|
"mi.content_rating = ANY($",
|
|
"LEFT JOIN episodes e ON e.content_id = h.media_item_id",
|
|
"JOIN media_items mi ON mi.content_id = COALESCE(NULLIF(e.series_id, ''), h.media_item_id)",
|
|
}
|
|
for _, fragment := range expectedFragments {
|
|
if !strings.Contains(query, fragment) {
|
|
t.Fatalf("expected query to contain %q, got:\n%s", fragment, query)
|
|
}
|
|
}
|
|
|
|
if len(args) < 6 {
|
|
t.Fatalf("expected snapshot, library, disabled-library, and rating args, got %d", len(args))
|
|
}
|
|
if got, ok := args[2].(time.Time); !ok || !got.Equal(snapshot) {
|
|
t.Fatalf("expected snapshot arg at index 2, got %#v", args[2])
|
|
}
|
|
}
|