feat: add package base price fallbacks

This commit is contained in:
2026-08-22 13:29:57 +07:00
parent 412e926a65
commit 30ddf25012
3 changed files with 196 additions and 27 deletions

View File

@@ -94,3 +94,62 @@ func TestPaketItemBasePriceFallbackParity(t *testing.T) {
})
}
}
func TestPaketServiceBasePriceFallbackParity(t *testing.T) {
tests := []struct {
name string
tariffPrice sql.NullFloat64
defaultPrice float64
serviceCode string
administrationPrice float64
administrationSource string
expectedPrice float64
expectedSource string
}{
{
name: "positive period tariff has highest priority",
tariffPrice: sql.NullFloat64{Float64: 150000, Valid: true},
defaultPrice: 100000, serviceCode: "LAB001",
expectedPrice: 150000, expectedSource: "TARIF_PERIODE",
},
{
name: "zero period tariff does not override master default",
tariffPrice: sql.NullFloat64{Float64: 0, Valid: true},
defaultPrice: 100000, serviceCode: "LAB001",
expectedPrice: 100000, expectedSource: "MASTER_DEFAULT",
},
{
name: "AN001 uses administration period fallback",
serviceCode: "an001", administrationPrice: 75000,
administrationSource: "ADM_PERIODE",
expectedPrice: 75000, expectedSource: "ADM_PERIODE",
},
{
name: "AD001 uses registration master fallback",
serviceCode: " AD001 ", administrationPrice: 50000,
administrationSource: "BIAYA_ADMIN",
expectedPrice: 50000, expectedSource: "BIAYA_ADMIN",
},
{
name: "non administration service does not use administration fallback",
serviceCode: "LAB001", administrationPrice: 50000,
administrationSource: "BIAYA_ADMIN",
expectedPrice: 0, expectedSource: "NOT_AVAILABLE",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
price, source := paketServiceBasePrice(
test.tariffPrice,
test.defaultPrice,
test.serviceCode,
test.administrationPrice,
test.administrationSource,
)
if price != test.expectedPrice || source != test.expectedSource {
t.Fatalf("price=%v source=%q want price=%v source=%q", price, source, test.expectedPrice, test.expectedSource)
}
})
}
}