41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package handler
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"io"
|
||
|
|
"net/http"
|
||
|
|
"net/http/httptest"
|
||
|
|
"strings"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestElderlySelfCareReturnsRawResponse(t *testing.T) {
|
||
|
|
client, seenPath := newTestClient(t, `{"code":"01","message":"操作成功","data":[{"checkId":"LNR-1","jc":"1","zpfs":"100"}]}`)
|
||
|
|
h := NewElderlyHandler(client)
|
||
|
|
|
||
|
|
req := httptest.NewRequest(http.MethodGet, "/api/elderly/self-care?idCard=TEST-ID&phrId=PHR-1", nil)
|
||
|
|
rec := httptest.NewRecorder()
|
||
|
|
h.SelfCare(rec, req)
|
||
|
|
|
||
|
|
if rec.Code != http.StatusOK {
|
||
|
|
t.Fatalf("status = %d", rec.Code)
|
||
|
|
}
|
||
|
|
if *seenPath != "/osi/api/auto/lnr/query" {
|
||
|
|
t.Fatalf("osi path = %q", *seenPath)
|
||
|
|
}
|
||
|
|
body, _ := io.ReadAll(rec.Body)
|
||
|
|
if !strings.Contains(string(body), `"zpfs":"100"`) {
|
||
|
|
t.Fatalf("body missing assessment content: %s", body)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestElderlySelfCareRequiresIDCard(t *testing.T) {
|
||
|
|
h := NewElderlyHandler(nil)
|
||
|
|
req := httptest.NewRequest(http.MethodGet, "/api/elderly/self-care?phrId=PHR-1", nil)
|
||
|
|
rec := httptest.NewRecorder()
|
||
|
|
h.SelfCare(rec, req)
|
||
|
|
|
||
|
|
if rec.Code != http.StatusBadRequest {
|
||
|
|
t.Fatalf("status = %d, want 400", rec.Code)
|
||
|
|
}
|
||
|
|
}
|