refactor(stats): slim final daily mileage table
This commit is contained in:
@@ -101,21 +101,27 @@ func TestProjectDailyMileageSelectsCandidateAndMarksSource(t *testing.T) {
|
||||
for _, want := range []string{
|
||||
"INSERT INTO vehicle_daily_mileage",
|
||||
"FROM vehicle_daily_mileage_source s",
|
||||
"LEFT JOIN vehicle_data_source ds",
|
||||
"ORDER BY COALESCE(ds.trust_priority, 100)",
|
||||
"JOIN vehicle_data_source ds",
|
||||
"ds.id",
|
||||
"ORDER BY ds.trust_priority",
|
||||
"s.quality_status = '" + QualityOK + "'",
|
||||
"s.daily_mileage_km BETWEEN 0 AND",
|
||||
"ds.latest_source_endpoint",
|
||||
} {
|
||||
if !strings.Contains(projectFinal, want) {
|
||||
t.Fatalf("project query missing %q: %s", want, projectFinal)
|
||||
}
|
||||
}
|
||||
if strings.Contains(projectFinal, "COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)") {
|
||||
t.Fatalf("project query should not fallback to source endpoint: %s", projectFinal)
|
||||
}
|
||||
if strings.Contains(projectFinal, ", s.source_endpoint") {
|
||||
t.Fatalf("project query should only project latest_source_endpoint: %s", projectFinal)
|
||||
for _, forbidden := range []string{
|
||||
"trusted_source_key",
|
||||
"trusted_phone",
|
||||
"trusted_source_endpoint",
|
||||
"first_total_mileage_km",
|
||||
"sample_count)",
|
||||
"ds.latest_source_endpoint",
|
||||
} {
|
||||
if strings.Contains(projectFinal, forbidden) {
|
||||
t.Fatalf("project query should not use final-table field %q: %s", forbidden, projectFinal)
|
||||
}
|
||||
}
|
||||
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)
|
||||
@@ -129,8 +135,8 @@ func TestProjectDailyMileageSelectsCandidateAndMarksSource(t *testing.T) {
|
||||
"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)",
|
||||
"ds.enabled = 1",
|
||||
"ORDER BY ds.trust_priority",
|
||||
"LIMIT 1",
|
||||
} {
|
||||
if !strings.Contains(markSelected, want) {
|
||||
|
||||
Reference in New Issue
Block a user