feat(mapping): 完成 PHIS 健康档案转换(T-212)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package source
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDecodeHealthRecordTaskKeepsBusinessFieldsAndDropsCredentials(t *testing.T) {
|
||||
raw, err := os.ReadFile("testdata/health_record.json")
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile: %v", err)
|
||||
}
|
||||
|
||||
task, err := DecodeHealthRecordTask(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("DecodeHealthRecordTask: %v", err)
|
||||
}
|
||||
if task.ArchID != "ARCH-001" || task.BusinessID != "BUSINESS-001" || task.EMPIID != "EMPI-001" || task.PHRID != "PHR-001" {
|
||||
t.Fatalf("identifiers = %#v", task)
|
||||
}
|
||||
if task.SourceRecordID() != "ARCH-001" {
|
||||
t.Fatalf("SourceRecordID = %q", task.SourceRecordID())
|
||||
}
|
||||
if task.Doctor.DoctorID != "DOC001" || task.Doctor.RealName != "测试医生" {
|
||||
t.Fatalf("doctor = %#v", task.Doctor)
|
||||
}
|
||||
if task.Record.IDCard != "440000********1234" || task.Record.AddressNumber != "1号" {
|
||||
t.Fatalf("record = %#v", task.Record)
|
||||
}
|
||||
|
||||
sanitized, err := json.Marshal(task)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal: %v", err)
|
||||
}
|
||||
if strings.Contains(string(sanitized), "sxtAccount") || strings.Contains(string(sanitized), "sxtPassword") || strings.Contains(string(sanitized), "IGNORED_") {
|
||||
t.Fatalf("credentials survived decoding: %s", sanitized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeHealthRecordTaskRejectsMissingStableArchiveID(t *testing.T) {
|
||||
raw := []byte(`{"code":200,"data":{"record":{"idCard":"440000********1234"},"businessId":"BUSINESS-001"}}`)
|
||||
|
||||
_, err := DecodeHealthRecordTask(raw)
|
||||
if err == nil || !strings.Contains(err.Error(), "archId is required") {
|
||||
t.Fatalf("error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeHealthRecordTaskRejectsFailedPHISResponse(t *testing.T) {
|
||||
raw := []byte(`{"code":500,"msg":"failed","data":{"archId":"ARCH-001"}}`)
|
||||
|
||||
_, err := DecodeHealthRecordTask(raw)
|
||||
if err == nil || !strings.Contains(err.Error(), "phis response code=500") {
|
||||
t.Fatalf("error = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user