feat: add package base prices
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package repository
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPaketListWhereParity(t *testing.T) {
|
||||
where, args := paketListWhere(PaketListParams{
|
||||
@@ -43,3 +46,51 @@ func TestLaravelDateJSONParity(t *testing.T) {
|
||||
t.Fatalf("zero date=%q", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaketItemBasePriceFallbackParity(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
het string
|
||||
defaultPrice float64
|
||||
baseCost float64
|
||||
categoryID int
|
||||
medicine sql.NullFloat64
|
||||
setting sql.NullFloat64
|
||||
medicalSupply sql.NullFloat64
|
||||
expected float64
|
||||
}{
|
||||
{
|
||||
name: "HET uses default price", het: "Y", defaultPrice: 1234.56,
|
||||
expected: 1234.56,
|
||||
},
|
||||
{
|
||||
name: "medicine uses tier margin", baseCost: 1000, categoryID: 1,
|
||||
medicine: sql.NullFloat64{Float64: 12.5, Valid: true},
|
||||
setting: sql.NullFloat64{Float64: 20, Valid: true}, expected: 1125,
|
||||
},
|
||||
{
|
||||
name: "medicine falls back to system setting", baseCost: 1000, categoryID: 1,
|
||||
setting: sql.NullFloat64{Float64: 20, Valid: true}, expected: 1200,
|
||||
},
|
||||
{
|
||||
name: "medical supply uses its margin", baseCost: 1000, categoryID: 2,
|
||||
medicalSupply: sql.NullFloat64{Float64: 15, Valid: true}, expected: 1150,
|
||||
},
|
||||
{
|
||||
name: "other category uses rounded default", defaultPrice: 1234.56,
|
||||
categoryID: 3, expected: 1235,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
actual := paketItemBasePrice(
|
||||
test.het, test.defaultPrice, test.baseCost, test.categoryID,
|
||||
test.medicine, test.setting, test.medicalSupply,
|
||||
)
|
||||
if actual != test.expected {
|
||||
t.Fatalf("base price=%v want=%v", actual, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user