97 lines
2.7 KiB
Go
97 lines
2.7 KiB
Go
package repository
|
|
|
|
import (
|
|
"database/sql"
|
|
"testing"
|
|
)
|
|
|
|
func TestPaketListWhereParity(t *testing.T) {
|
|
where, args := paketListWhere(PaketListParams{
|
|
Search: "MCU", Code: "DISP", CareType: "RJ", Status: 2,
|
|
Active: "N", StartDate: "2026-08-01", EndDate: "2026-08-31",
|
|
})
|
|
const expected = "WHERE ph.StatusID = ? AND ph.NA = ? AND ph.Nama LIKE ? AND ph.PaketID LIKE ? AND ph.RJ = 1 AND ph.TglSampai >= ? AND ph.TglDari <= ?"
|
|
if where != expected {
|
|
t.Fatalf("where=%q", where)
|
|
}
|
|
if len(args) != 6 || args[0] != 2 || args[1] != "N" || args[2] != "%MCU%" || args[3] != "%DISP%" {
|
|
t.Fatalf("args=%v", args)
|
|
}
|
|
}
|
|
|
|
func TestPHPNumberFormatParity(t *testing.T) {
|
|
tests := []struct {
|
|
value float64
|
|
decimals int
|
|
expected string
|
|
}{
|
|
{500000, 0, "500,000"},
|
|
{1609.5, 2, "1,609.50"},
|
|
{1448.55, 2, "1,448.55"},
|
|
{0, 2, "0.00"},
|
|
{-1234.5, 0, "-1,235"},
|
|
}
|
|
for _, test := range tests {
|
|
if actual := phpNumberFormat(test.value, test.decimals); actual != test.expected {
|
|
t.Fatalf("phpNumberFormat(%v, %d)=%q want=%q", test.value, test.decimals, actual, test.expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLaravelDateJSONParity(t *testing.T) {
|
|
if actual := laravelDateJSON("2026-08-05 17:05:03"); actual != "2026-08-05T10:05:03.000000Z" {
|
|
t.Fatalf("date=%q", actual)
|
|
}
|
|
if actual := laravelDateJSON("0000-00-00 00:00:00"); actual != "-000001-11-29T16:52:48.000000Z" {
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|