adjust response depretitation v2

This commit is contained in:
giovanni
2026-06-08 12:30:51 +07:00
parent 61d375a59a
commit 217f35b250
7 changed files with 210 additions and 69 deletions
@@ -50,7 +50,7 @@ type ExpenseDepreciationV2MetaDTO struct {
}
type ExpenseDepreciationV2RowDTO struct {
Date string `json:"date"`
Date string `json:"date"`
DepreciationPercentEffective float64 `json:"depreciation_percent_effective"`
DepreciationValue float64 `json:"depreciation_value"`
PulletCostDayNTotal float64 `json:"pullet_cost_day_n_total"`
@@ -60,7 +60,6 @@ type ExpenseDepreciationV2RowDTO struct {
TotalValuePulletAfterDepreciation float64 `json:"total_value_pullet_after_depreciation"`
StandardEffectiveDate string `json:"standard_effective_date,omitempty"`
TotalPopulation float64 `json:"total_population"`
Components any `json:"components"`
}
func NewExpenseDepreciationFiltersDTO(area, location, projectFlockID, period string) ExpenseDepreciationFiltersDTO {
@@ -0,0 +1,51 @@
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))
}
}