fix: Change geojson properties structure
This commit is contained in:
@@ -843,8 +843,12 @@ func TestDatasetService_GeoJSON_DistrictJoin(t *testing.T) {
|
||||
if f.Properties["kato"] != "710000000" || f.Properties["name"] != "Astana" {
|
||||
t.Fatalf("unexpected properties: %+v", f.Properties)
|
||||
}
|
||||
if f.Properties["2020-01-01"] != 100.0 || f.Properties["2021-01-01"] != 150.0 {
|
||||
t.Fatalf("year values not flattened into properties: %+v", f.Properties)
|
||||
data, ok := f.Properties["data"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("observations not nested under data: %+v", f.Properties)
|
||||
}
|
||||
if data["2020-01-01"] != 100.0 || data["2021-01-01"] != 150.0 {
|
||||
t.Fatalf("year values not nested under data: %+v", data)
|
||||
}
|
||||
|
||||
// The whole thing must marshal to valid GeoJSON.
|
||||
@@ -867,6 +871,7 @@ func TestDatasetService_GeoJSON_UsesDatasetGeometry(t *testing.T) {
|
||||
{KatoCode: "710000000", Date: "2020-01-01", Value: &v},
|
||||
{KatoCode: "710000000", Date: "2021-01-01", Value: &v},
|
||||
}
|
||||
repo.districts["710000000"] = domain.District{Kato: "710000000", Name: "Astana"}
|
||||
|
||||
svc := newDatasetService(repo, &stubStore{}, true)
|
||||
fc, err := svc.GeoJSON(ctx, id)
|
||||
@@ -880,16 +885,28 @@ func TestDatasetService_GeoJSON_UsesDatasetGeometry(t *testing.T) {
|
||||
if string(f.Geometry) != string(geom) {
|
||||
t.Fatalf("feature should reuse dataset geometry, got %s", f.Geometry)
|
||||
}
|
||||
// Properties hold only the observations, keyed by KATO at the top level.
|
||||
if _, ok := f.Properties["name"]; ok {
|
||||
t.Fatalf("properties should contain only observations, got metadata: %+v", f.Properties)
|
||||
// Properties nest the observations under `data`, keyed by KATO; each KATO
|
||||
// entry carries the district name and its own nested `data` map.
|
||||
if _, flat := f.Properties["710000000"]; flat {
|
||||
t.Fatalf("observations must be nested under data, not at top level: %+v", f.Properties)
|
||||
}
|
||||
kato, ok := f.Properties["710000000"].(map[string]any)
|
||||
data, ok := f.Properties["data"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("observations not keyed by KATO at top level: %+v", f.Properties)
|
||||
t.Fatalf("observations not nested under data: %+v", f.Properties)
|
||||
}
|
||||
if kato["2020-01-01"] != 42.0 || kato["2021-01-01"] != 42.0 {
|
||||
t.Fatalf("year values missing under KATO: %+v", kato)
|
||||
kato, ok := data["710000000"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("observations not keyed by KATO under data: %+v", data)
|
||||
}
|
||||
if kato["name"] != "Astana" {
|
||||
t.Fatalf("district name missing per KATO: %+v", kato)
|
||||
}
|
||||
values, ok := kato["data"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("per-KATO observations not nested under data: %+v", kato)
|
||||
}
|
||||
if values["2020-01-01"] != 42.0 || values["2021-01-01"] != 42.0 {
|
||||
t.Fatalf("year values missing under KATO data: %+v", values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,8 +942,15 @@ func TestDatasetService_KatoGeoJSON_IgnoresDatasetGeometry(t *testing.T) {
|
||||
if f.Properties["kato"] != "710000000" || f.Properties["name"] != "Astana" {
|
||||
t.Fatalf("unexpected properties: %+v", f.Properties)
|
||||
}
|
||||
if f.Properties["2020-01-01"] != 100.0 {
|
||||
t.Fatalf("observation value not mapped onto polygon: %+v", f.Properties)
|
||||
data, ok := f.Properties["data"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("observations must be nested under data: %+v", f.Properties)
|
||||
}
|
||||
if data["2020-01-01"] != 100.0 {
|
||||
t.Fatalf("observation value not mapped under data: %+v", data)
|
||||
}
|
||||
if _, flat := f.Properties["2020-01-01"]; flat {
|
||||
t.Fatalf("observation dates must not be flat in properties: %+v", f.Properties)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user