refactor(collections): rule evaluators take the real row; both 45-field converter twins deleted

checkRulesAgainstBook/evaluateRule and the service's EvaluateRules
existed in two parallel universes: one over database.MediaItems (what
every query actually returns) and one over ListMediaItemsRow (what two
hand-written 45-field mediaItemsToListMediaItemsRow converters
produced — verbatim twins in the handler and the dashboard service,
with a URL-resolution side effect baked into a "converter"). The rule
fields (genre/series/author/language/publisher/copyright_year/tags)
all exist on MediaItems, so the evaluators now take the real row and
the converters, their three call-site loops, and the dead
ApplyAutoAssignRules entry point (zero callers) are gone.

The rules surface is wire-covered by the collections rules scenarios;
handlers+services suites and the full pin/H1/H3 battery green.
This commit is contained in:
John O'Keefe committed 2026-10-17 16:48:39 -04:00
1 parent b47a2b86a7
commit 18727fef93
7 files changed
+54 -193

No files matched your search

+8 -8
View File
@@ -10,7 +10,7 @@ import (
func TestEvaluateRules_Equality(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
}
@@ -42,7 +42,7 @@ func TestEvaluateRules_Equality(t *testing.T) {
func TestEvaluateRules_NoMatch(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
Genre: pgtype.Text{String: "Fantasy", Valid: true},
}
@@ -74,7 +74,7 @@ func TestEvaluateRules_NoMatch(t *testing.T) {
func TestEvaluateRules_Contains(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
Series: pgtype.Text{String: "The Expanse", Valid: true},
}
@@ -106,7 +106,7 @@ func TestEvaluateRules_Contains(t *testing.T) {
func TestEvaluateRules_PriorityOrder(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
Series: pgtype.Text{String: "Foundation", Valid: true},
}
@@ -150,7 +150,7 @@ func TestEvaluateRules_PriorityOrder(t *testing.T) {
func TestEvaluateRules_CopyrightYear(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
CopyrightYear: pgtype.Int4{Int32: 2020, Valid: true},
}
@@ -178,7 +178,7 @@ func TestEvaluateRules_CopyrightYear(t *testing.T) {
func TestEvaluateRules_MissingField(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{}
mediaItem := database.MediaItems{}
rules := []Rule{
{
@@ -204,7 +204,7 @@ func TestEvaluateRules_MissingField(t *testing.T) {
func TestEvaluateRules_CaseInsensitive(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
Genre: pgtype.Text{String: "science fiction", Valid: true},
}
@@ -232,7 +232,7 @@ func TestEvaluateRules_CaseInsensitive(t *testing.T) {
func TestEvaluateRules_PriorityBoost(t *testing.T) {
service := &CollectionService{}
mediaItem := database.ListMediaItemsRow{
mediaItem := database.MediaItems{
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
}