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) } }) } } 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) } }) } }