package plan3test import ( "encoding/json" "net/http" "os" "testing" "github.com/go-chi/chi/v5" ) func TestPreviewPassContract(t *testing.T) { f := newFixture(t) found := false must(t, chi.Walk(f.Store.PersonAPIHandler().(chi.Routes), func(method, path string, _ http.Handler, _ ...func(http.Handler) http.Handler) error { if method == "POST" && path == "/tasks/{id}/preview-pass" { found = true } return nil })) if !found { t.Fatal("preview pass route missing") } raw, err := os.ReadFile("../../docs/api/equipo-v1.openapi.json") must(t, err) var doc map[string]any must(t, json.Unmarshal(raw, &doc)) op := doc["paths"].(map[string]any)["/tasks/{id}/preview-pass"].(map[string]any)["post"].(map[string]any) if op["operationId"] != "post_tasks_id_preview_pass" { t.Fatal("wrong operation") } security := op["security"].([]any) if len(security) != 1 || security[0].(map[string]any)["personBearer"] == nil { t.Fatal("pass must be device-only") } request := op["requestBody"].(map[string]any) if request["x-maxBytes"] != float64(4096) || request["x-rejectUnknownFields"] != true { t.Fatal("unbounded pass input") } if op["responses"].(map[string]any)["201"] == nil { t.Fatal("missing created response") } schema := doc["components"].(map[string]any)["schemas"].(map[string]any)["PreviewPass"].(map[string]any) if schema["additionalProperties"] != false || len(schema["required"].([]any)) != 5 || len(schema["properties"].(map[string]any)) != 5 { t.Fatal("unexpected pass representation") } for name, maximum := range map[string]float64{"expires_in": 60, "grant_expires_in": 900} { field := schema["properties"].(map[string]any)[name].(map[string]any) if field["type"] != "integer" || field["minimum"] != float64(1) || field["maximum"] != maximum { t.Fatal("relative lifetime bounds", name, field) } } }