Download this file
| 1 | package web |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "net/http/httptest" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/home/connect" |
| 10 | ) |
| 11 | |
| 12 | // GET /api/team is Alta's readiness probe for a team Base (seeded mode). |
| 13 | func TestTeamProbe(t *testing.T) { |
| 14 | probe := func(a *app) *httptest.ResponseRecorder { |
| 15 | w := httptest.NewRecorder() |
| 16 | a.teamProbe(w, httptest.NewRequest("GET", "/api/team", nil)) |
| 17 | return w |
| 18 | } |
| 19 | a, _, _ := teamApp(t) |
| 20 | if w := probe(a); w.Code != 404 { |
| 21 | t.Fatalf("without Oficina ID: %d %s", w.Code, w.Body) |
| 22 | } |
| 23 | a.cfg.Home = &connect.DecodedCredentials{ConsumerID: "campbells-base"} |
| 24 | w := probe(a) |
| 25 | if w.Code != 200 || w.Header().Get("Content-Type") != "application/json" || w.Header().Get("Cache-Control") != "no-store" || strings.Contains(w.Body.String(), "@") { |
| 26 | t.Fatalf("%d %v %s", w.Code, w.Header(), w.Body) |
| 27 | } |
| 28 | var got map[string]any |
| 29 | if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil || len(got) != 4 || got["team_mode"] != false || got["seeded"] != true || got["consumer"] != "campbells-base" || got["roster"] != "ok" { |
| 30 | t.Fatalf("%v %s", err, w.Body) |
| 31 | } |
| 32 | if _, err := a.db.Exec(`UPDATE members SET role = 'member' WHERE role = 'owner'`); err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | if w := probe(a); !strings.Contains(w.Body.String(), `"roster":"owner-pending"`) { |
| 36 | t.Fatalf("%s", w.Body) |
| 37 | } |
| 38 | } |
| 39 | |