Files
ez-api/internal/api/response_test.go
zenfun dd32ee817d test(api): align tests with new envelope codes
Update API handler tests to expect numeric `code`, `success` messages, and
new envelope fields (`trace_id`, `details`), matching recent response
envelope changes.
2026-01-10 00:39:35 +08:00

30 lines
686 B
Go

package api
import (
"encoding/json"
"net/http/httptest"
"testing"
)
type testEnvelope struct {
Code int `json:"code"`
Data json.RawMessage `json:"data"`
Message string `json:"message"`
TraceID string `json:"trace_id"`
Details any `json:"details,omitempty"`
}
func decodeEnvelope(t *testing.T, rr *httptest.ResponseRecorder, out any) testEnvelope {
t.Helper()
var env testEnvelope
if err := json.Unmarshal(rr.Body.Bytes(), &env); err != nil {
t.Fatalf("decode envelope: %v", err)
}
if out != nil {
if err := json.Unmarshal(env.Data, out); err != nil {
t.Fatalf("decode envelope data: %v", err)
}
}
return env
}