oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package plan3test
2
3import (
4 "encoding/json"
5 "net/http"
6 "os"
7 "testing"
8
9 "github.com/go-chi/chi/v5"
10)
11
12func TestPreviewPassContract(t *testing.T) {
13 f := newFixture(t)
14 found := false
15 must(t, chi.Walk(f.Store.PersonAPIHandler().(chi.Routes), func(method, path string, _ http.Handler, _ ...func(http.Handler) http.Handler) error {
16 if method == "POST" && path == "/tasks/{id}/preview-pass" {
17 found = true
18 }
19 return nil
20 }))
21 if !found {
22 t.Fatal("preview pass route missing")
23 }
24 raw, err := os.ReadFile("../../docs/api/equipo-v1.openapi.json")
25 must(t, err)
26 var doc map[string]any
27 must(t, json.Unmarshal(raw, &doc))
28 op := doc["paths"].(map[string]any)["/tasks/{id}/preview-pass"].(map[string]any)["post"].(map[string]any)
29 if op["operationId"] != "post_tasks_id_preview_pass" {
30 t.Fatal("wrong operation")
31 }
32 security := op["security"].([]any)
33 if len(security) != 1 || security[0].(map[string]any)["personBearer"] == nil {
34 t.Fatal("pass must be device-only")
35 }
36 request := op["requestBody"].(map[string]any)
37 if request["x-maxBytes"] != float64(4096) || request["x-rejectUnknownFields"] != true {
38 t.Fatal("unbounded pass input")
39 }
40 if op["responses"].(map[string]any)["201"] == nil {
41 t.Fatal("missing created response")
42 }
43 schema := doc["components"].(map[string]any)["schemas"].(map[string]any)["PreviewPass"].(map[string]any)
44 if schema["additionalProperties"] != false || len(schema["required"].([]any)) != 5 || len(schema["properties"].(map[string]any)) != 5 {
45 t.Fatal("unexpected pass representation")
46 }
47 for name, maximum := range map[string]float64{"expires_in": 60, "grant_expires_in": 900} {
48 field := schema["properties"].(map[string]any)[name].(map[string]any)
49 if field["type"] != "integer" || field["minimum"] != float64(1) || field["maximum"] != maximum {
50 t.Fatal("relative lifetime bounds", name, field)
51 }
52 }
53
54}
55