Files
cpone_midleware/internal/repository/lab_result_test.go

48 lines
1.5 KiB
Go

package repository
import (
"database/sql"
"testing"
"time"
)
func TestLabAgeCodeMatchesCarbonDateDiff(t *testing.T) {
birth := time.Date(1993, time.March, 4, 0, 0, 0, 0, time.UTC)
transaction := time.Date(2026, time.August, 19, 0, 0, 0, 0, time.UTC)
if got := labAgeCode(birth, transaction); got != "0330515" {
t.Fatalf("age code=%s, want 0330515", got)
}
endOfMonthBirth := time.Date(2025, time.January, 31, 0, 0, 0, 0, time.UTC)
marchFirst := time.Date(2025, time.March, 1, 0, 0, 0, 0, time.UTC)
if got := labAgeCode(endOfMonthBirth, marchFirst); got != "0000029" {
t.Fatalf("end-of-month age code=%s, want 0000029", got)
}
}
func TestFormatLabReferenceValue(t *testing.T) {
value := formatLabReferenceValue(
sql.NullString{},
sql.NullString{String: "12.5", Valid: true},
sql.NullString{String: "17.5", Valid: true},
)
if value == nil || *value != "12.5 - 17.5" {
t.Fatalf("reference=%v", value)
}
description := formatLabReferenceValue(sql.NullString{String: " Normal ", Valid: true}, sql.NullString{}, sql.NullString{})
if description == nil || *description != "Normal" {
t.Fatalf("description=%v", description)
}
}
func TestFindColumnIsCaseInsensitiveAndHonorsCandidatePriority(t *testing.T) {
columns := []string{"Lab_AnalyzerID", "AnalyzerID", "PROSES"}
if got := findColumn(columns, "AnalyzerID", "Lab_AnalyzerID"); got != "AnalyzerID" {
t.Fatalf("column=%q", got)
}
if got := findColumn(columns, "Proses"); got != "PROSES" {
t.Fatalf("column=%q", got)
}
}