Files
minstrel/internal/api/errors_test.go
T
bvandeusen dc43921bcc feat(api): package skeleton + error envelope
Introduces internal/api with Mount(), the {error:{code,message}}
response shape, and stubbed login/logout/me so later tasks can
land one handler at a time without breaking the build.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 20:57:09 -04:00

33 lines
824 B
Go

package api
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestWriteErr_EmitsJSONEnvelope(t *testing.T) {
w := httptest.NewRecorder()
writeErr(w, http.StatusBadRequest, "bad_request", "field x required")
if w.Code != http.StatusBadRequest {
t.Errorf("status = %d, want 400", w.Code)
}
if got := w.Header().Get("Content-Type"); got != "application/json" {
t.Errorf("content-type = %q, want application/json", got)
}
var body struct {
Error struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
t.Fatalf("decode: %v\nbody=%s", err, w.Body.String())
}
if body.Error.Code != "bad_request" || body.Error.Message != "field x required" {
t.Errorf("body = %+v", body)
}
}