package dto import ( "encoding/json" "testing" ) func TestExpenseDepreciationRowDTOComponentsJSONContract(t *testing.T) { v1 := ExpenseDepreciationRowDTO{ ProjectFlockID: 1, FarmName: "Farm A", Period: "2026-06-05", Components: map[string]any{"kandang_count": 1}, } rawV1, err := json.Marshal(v1) if err != nil { t.Fatalf("marshal v1 dto: %v", err) } var decodedV1 map[string]any if err := json.Unmarshal(rawV1, &decodedV1); err != nil { t.Fatalf("unmarshal v1 dto: %v", err) } if _, ok := decodedV1["components"]; !ok { t.Fatalf("expected v1 components to be present, got %s", string(rawV1)) } v2 := ExpenseDepreciationV2RowDTO{ Date: "2026-06-05", DepreciationPercentEffective: 10, DepreciationValue: 100, PulletCostDayNTotal: 1000, MultiplicationPercentage: 0.9, DayN: 2, ChickinDate: "2026-01-01", TotalValuePulletAfterDepreciation: 900, TotalPopulation: 100, } rawV2, err := json.Marshal(v2) if err != nil { t.Fatalf("marshal v2 dto: %v", err) } var decodedV2 map[string]any if err := json.Unmarshal(rawV2, &decodedV2); err != nil { t.Fatalf("unmarshal v2 dto: %v", err) } if _, ok := decodedV2["components"]; ok { t.Fatalf("expected v2 components to be omitted, got %s", string(rawV2)) } }