mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-06-01 19:01:37 +00:00
test(api/v2): use huma.ErrorModel for problem+json assertions
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/danielgtaylor/huma/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -43,7 +44,7 @@ func TestHuma_ErrorShapeIsRFC9457(t *testing.T) {
|
||||
ct := rec.Header().Get("Content-Type")
|
||||
assert.Contains(t, ct, "application/problem+json", "forbidden response must use RFC 9457 content type; got %q", ct)
|
||||
|
||||
var body humaErrorBody
|
||||
var body huma.ErrorModel
|
||||
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &body), "body: %s", rec.Body.String())
|
||||
assert.Equal(t, http.StatusForbidden, body.Status)
|
||||
assert.NotEmpty(t, body.Title, "title is required by RFC 9457")
|
||||
@@ -56,7 +57,7 @@ func TestHuma_ErrorShapeIsRFC9457(t *testing.T) {
|
||||
ct := rec.Header().Get("Content-Type")
|
||||
assert.Contains(t, ct, "application/problem+json", "validation response must use RFC 9457 content type; got %q", ct)
|
||||
|
||||
var body humaErrorBody
|
||||
var body huma.ErrorModel
|
||||
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &body), "body: %s", rec.Body.String())
|
||||
assert.Equal(t, http.StatusUnprocessableEntity, body.Status)
|
||||
require.NotEmpty(t, body.Errors, "validation errors must include structured per-field details")
|
||||
|
||||
@@ -41,19 +41,6 @@ func labelTokenFor(t *testing.T, u *user.User) string {
|
||||
return tok
|
||||
}
|
||||
|
||||
// humaErrorBody is the RFC 9457 problem+json shape Huma emits by default.
|
||||
// Fields are a subset — we only assert what's load-bearing for the tests.
|
||||
type humaErrorBody struct {
|
||||
Type string `json:"type"`
|
||||
Title string `json:"title"`
|
||||
Status int `json:"status"`
|
||||
Detail string `json:"detail"`
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Location string `json:"location"`
|
||||
} `json:"errors"`
|
||||
}
|
||||
|
||||
// TestHumaLabel mirrors the v1 webtest shape (see project_test.go's TestProject)
|
||||
// so the v2 contract can be read side-by-side with the v1 coverage. The goal
|
||||
// is to prove v2 is behaviourally compatible with v1 modulo the documented
|
||||
|
||||
Reference in New Issue
Block a user