| 1 | package plan3test |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/equipo/personapi" |
| 5 | "amadan.net/oficina/equipo/internal/wire/wireschema" |
| 6 | "encoding/json" |
| 7 | "os" |
| 8 | "reflect" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | func TestNotificationLegacyCardAndContract(t *testing.T) { |
| 14 | f := newFixture(t) |
| 15 | proposed(t, f) |
| 16 | list := apiRequest(t, f, owner, "GET", "/api/v1/conversation/cards", "", "", "") |
| 17 | expectHTTP(t, list, 200) |
| 18 | page := apiValue[personapi.Page[personapi.Card]](t, list) |
| 19 | if len(page.Items) == 0 { |
| 20 | t.Fatal("missing legacy fixture") |
| 21 | } |
| 22 | c := page.Items[0] |
| 23 | if strings.HasPrefix(c.ID, "c_") { |
| 24 | t.Fatal("legacy id collides with reserved thin prefix", c.ID) |
| 25 | } |
| 26 | response := apiRequest(t, f, owner, "GET", "/api/v1/cards/"+c.ID, "", "", "") |
| 27 | expectHTTP(t, response, 200) |
| 28 | got := apiValue[personapi.Card](t, response) |
| 29 | if !reflect.DeepEqual(c, got) { |
| 30 | t.Fatal("legacy projection changed", c, got) |
| 31 | } |
| 32 | raw, err := os.ReadFile("../../docs/api/equipo-v1.openapi.json") |
| 33 | must(t, err) |
| 34 | var doc map[string]any |
| 35 | must(t, json.Unmarshal(raw, &doc)) |
| 36 | schema := doc["paths"].(map[string]any)["/cards/{id}"].(map[string]any)["get"].(map[string]any)["responses"].(map[string]any)["200"].(map[string]any)["content"].(map[string]any)["application/json"].(map[string]any)["schema"].(map[string]any) |
| 37 | schemas := doc["components"].(map[string]any)["schemas"].(map[string]any) |
| 38 | must(t, wireschema.Validate(schemas, deviceJSON(t, got), schema, "legacy")) |
| 39 | raw, err = os.ReadFile("../../native/apple/Tests/EquipoKitTests/Fixtures/thin/snapshot.json") |
| 40 | must(t, err) |
| 41 | var snapshot map[string]any |
| 42 | must(t, json.Unmarshal(raw, &snapshot)) |
| 43 | for _, card := range snapshot["cards"].([]any) { |
| 44 | must(t, wireschema.Validate(schemas, card, schema, "thin")) |
| 45 | } |
| 46 | } |
| 47 | |