feat: add cooperation tariff APIs
This commit is contained in:
81
internal/repository/tarif_kerjasama_test.go
Normal file
81
internal/repository/tarif_kerjasama_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func TestTarifKerjasamaListWhere(t *testing.T) {
|
||||
tarifID := int64(1098)
|
||||
where, args := tarifKerjasamaListWhere(TarifKerjasamaListParams{
|
||||
Search: "medicare", PerusahaanID: "COMP-001", TarifID: &tarifID,
|
||||
})
|
||||
const expected = "WHERE p.NA = 'N' AND (p.Nama LIKE ? OR p.KodePerusahaan LIKE ?\n\t\t\tOR pt.PerusahaanID LIKE ? OR pt.PenanggungJawab LIKE ?) AND pt.PerusahaanID = ? AND pt.Perusahaan_TarifID = ?"
|
||||
if where != expected {
|
||||
t.Fatalf("where=%q", where)
|
||||
}
|
||||
if len(args) != 6 || args[0] != "%medicare%" || args[4] != "COMP-001" || args[5] != int64(1098) {
|
||||
t.Fatalf("args=%v", args)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupTarifKerjasamaLayanan(t *testing.T) {
|
||||
rows := []tarifKerjasamaLayananRow{
|
||||
tarifKerjasamaTestRow(1, "LAB-001", "KLS-1", "Kelas I", "125000.00"),
|
||||
tarifKerjasamaTestRow(2, "LAB-001", "KLS-2", "", "115000.00"),
|
||||
tarifKerjasamaTestRow(3, "LAB-002", "KLS-1", "Kelas I", "50000.00"),
|
||||
}
|
||||
|
||||
result := groupTarifKerjasamaLayanan(rows)
|
||||
if len(result) != 2 {
|
||||
t.Fatalf("services=%d want=2", len(result))
|
||||
}
|
||||
if result[0].LayananID == nil || *result[0].LayananID != "LAB-001" || result[0].JumlahDetail != 2 {
|
||||
t.Fatalf("first service=%+v", result[0])
|
||||
}
|
||||
if result[0].Detail[0].Harga != 125000 || result[0].Detail[1].NamaKelas == nil || *result[0].Detail[1].NamaKelas != "KLS-2" {
|
||||
t.Fatalf("details=%+v", result[0].Detail)
|
||||
}
|
||||
if result[1].JumlahDetail != 1 || result[1].Detail[0].Harga != 50000 {
|
||||
t.Fatalf("second service=%+v", result[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestNullDecimalPtr(t *testing.T) {
|
||||
if nullDecimalPtr(sql.NullString{}) != nil {
|
||||
t.Fatal("invalid SQL null must map to nil")
|
||||
}
|
||||
value := nullDecimalPtr(sql.NullString{String: "12.50", Valid: true})
|
||||
if value == nil || *value != 12.5 {
|
||||
t.Fatalf("value=%v", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMySQLMissingDynamicTariffTableError(t *testing.T) {
|
||||
err := &mysql.MySQLError{Number: 1146, Message: "table does not exist"}
|
||||
if !isMySQLMissingTable(err) {
|
||||
t.Fatalf("unexpected MySQL error: %v", err)
|
||||
}
|
||||
if isMySQLMissingTable(&mysql.MySQLError{Number: 1054, Message: "unknown column"}) {
|
||||
t.Fatal("non-1146 MySQL errors must not be treated as a missing table")
|
||||
}
|
||||
}
|
||||
|
||||
func tarifKerjasamaTestRow(id int64, layananID, kelasID, namaKelas, harga string) tarifKerjasamaLayananRow {
|
||||
return tarifKerjasamaLayananRow{
|
||||
TarifLayananID: id,
|
||||
LayananID: sql.NullString{String: layananID, Valid: true},
|
||||
NamaLayanan: sql.NullString{String: "Layanan " + layananID, Valid: true},
|
||||
JenisLayananID: sql.NullString{String: "LAB", Valid: true},
|
||||
NamaJenis: sql.NullString{String: "Laboratorium", Valid: true},
|
||||
KelasID: sql.NullString{String: kelasID, Valid: true},
|
||||
NamaKelas: sql.NullString{String: namaKelas, Valid: namaKelas != ""},
|
||||
Harga: sql.NullString{String: harga, Valid: true},
|
||||
DiskonRJ: sql.NullString{String: "10", Valid: true},
|
||||
DiskonRI: sql.NullString{String: "5", Valid: true},
|
||||
ShareDokter: sql.NullString{String: "25000", Valid: true},
|
||||
ShareRS: sql.NullString{String: "100000", Valid: true},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user