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:
1 parent
b47a2b86a7
commit
18727fef93
7 files changed
+54
-193
No files matched your search
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func TestEvaluateRule_Equals_StringMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestEvaluateRule_Equals_StringMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_Equals_NoMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Fantasy", Valid: true},
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestEvaluateRule_Equals_NoMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_NotEquals_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Fantasy", Valid: true},
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestEvaluateRule_NotEquals_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_NotEquals_NoMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestEvaluateRule_NotEquals_NoMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_Contains_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Author: pgtype.Text{String: "Isaac Asimov", Valid: true},
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestEvaluateRule_Contains_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_Contains_NoMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Author: pgtype.Text{String: "Isaac Asimov", Valid: true},
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestEvaluateRule_Contains_NoMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_NotContains_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Author: pgtype.Text{String: "Isaac Asimov", Valid: true},
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestEvaluateRule_NotContains_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_StartsWith_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Series: pgtype.Text{String: "Foundation", Valid: true},
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestEvaluateRule_StartsWith_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_StartsWith_NoMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Series: pgtype.Text{String: "Foundation", Valid: true},
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestEvaluateRule_StartsWith_NoMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_EndsWith_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Series: pgtype.Text{String: "Foundation", Valid: true},
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func TestEvaluateRule_EndsWith_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_GreaterThan_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
CopyrightYear: pgtype.Int4{Int32: 2021, Valid: true},
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func TestEvaluateRule_GreaterThan_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_GreaterThan_NoMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
CopyrightYear: pgtype.Int4{Int32: 1999, Valid: true},
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestEvaluateRule_GreaterThan_NoMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_LessThan_Matches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
CopyrightYear: pgtype.Int4{Int32: 1999, Valid: true},
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func TestEvaluateRule_LessThan_Matches(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_LessThan_NoMatch(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
CopyrightYear: pgtype.Int4{Int32: 2021, Valid: true},
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func TestEvaluateRule_LessThan_NoMatch(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_NullField(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{Valid: false}, // NULL
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func TestCompareValues_NumericEdgeCases(t *testing.T) {
|
||||
|
||||
func TestCheckRulesAgainstBook_MatchesFirstRule(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestCheckRulesAgainstBook_MatchesFirstRule(t *testing.T) {
|
||||
|
||||
func TestCheckRulesAgainstBook_MatchesSecondRule(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Fantasy", Valid: true},
|
||||
Author: pgtype.Text{String: "Isaac Asimov", Valid: true},
|
||||
CopyrightYear: pgtype.Int4{Int32: 2021, Valid: true},
|
||||
@@ -245,7 +245,7 @@ func TestCheckRulesAgainstBook_MatchesSecondRule(t *testing.T) {
|
||||
|
||||
func TestCheckRulesAgainstBook_NoMatches(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Mystery", Valid: true},
|
||||
Author: pgtype.Text{String: "Agatha Christie", Valid: true},
|
||||
CopyrightYear: pgtype.Int4{Int32: 1950, Valid: true},
|
||||
@@ -270,7 +270,7 @@ func TestCheckRulesAgainstBook_NoMatches(t *testing.T) {
|
||||
|
||||
func TestCheckRulesAgainstBook_EmptyRules(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ func TestComplexRule_MultipleConditions(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
|
||||
// Book: "Foundation" by Isaac Asimov, Sci-Fi, 1951
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Title: "Foundation",
|
||||
Author: pgtype.Text{String: "Isaac Asimov", Valid: true},
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
@@ -371,7 +371,7 @@ func TestComplexRule_MultipleConditions(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_InvalidOperator(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ func TestEvaluateRule_InvalidOperator(t *testing.T) {
|
||||
|
||||
func TestEvaluateRule_NonExistentField(t *testing.T) {
|
||||
handler := &CollectionHandler{}
|
||||
item := database.ListMediaItemsRow{
|
||||
item := database.MediaItems{
|
||||
Genre: pgtype.Text{String: "Science Fiction", Valid: true},
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user