fix(stats): guard daily mileage source selection marking
This commit is contained in:
@@ -119,4 +119,27 @@ func TestProjectDailyMileageSelectsCandidateAndMarksSource(t *testing.T) {
|
||||
if !strings.Contains(markSelected, "UPDATE vehicle_daily_mileage_source s") || !strings.Contains(markSelected, "SET s.is_selected = 1") {
|
||||
t.Fatalf("mark query should flag the elected source: %s", markSelected)
|
||||
}
|
||||
if strings.Contains(markSelected, "JOIN vehicle_daily_mileage m") {
|
||||
t.Fatalf("mark query should not rejoin final mileage for candidate selection: %s", markSelected)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"JOIN (",
|
||||
"SELECT",
|
||||
"s2.source_key",
|
||||
"s2.quality_status = '" + QualityOK + "'",
|
||||
"s2.daily_mileage_km BETWEEN 0 AND",
|
||||
"COALESCE(ds.enabled, 1) = 1",
|
||||
"ORDER BY COALESCE(ds.trust_priority, 100)",
|
||||
"LIMIT 1",
|
||||
} {
|
||||
if !strings.Contains(markSelected, want) {
|
||||
t.Fatalf("mark query missing %q: %s", want, markSelected)
|
||||
}
|
||||
}
|
||||
if len(exec.calls[2].args) != 7 {
|
||||
t.Fatalf("mark query args = %d, want 7", len(exec.calls[2].args))
|
||||
}
|
||||
if got := exec.calls[2].args[3]; got != maxSelectedDailyMileageKM {
|
||||
t.Fatalf("mark query max mileage arg = %#v, want %d", got, maxSelectedDailyMileageKM)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user