package main import ( "encoding/json" "net/http" "strings" "testing" ) // The integrations catalog is public (like /api/apps): the embedded registry, // verbatim, so clients can render the connect catalog and the write ops' // consent lines. func TestIntegrationsEndpoint(t *testing.T) { ts, _ := newTestServer(t) resp, err := http.Get(ts.URL + "/api/integrations") if err != nil { t.Fatal(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { t.Fatalf("status %d", resp.StatusCode) } if ct := resp.Header.Get("Content-Type"); !strings.Contains(ct, "application/json") { t.Fatalf("content-type %q", ct) } var out struct { Schema int `json:"schema"` Services []struct { ID string `json:"id"` Ops []struct { ID string `json:"id"` Access string `json:"access"` Confirm string `json:"confirm"` } `json:"ops"` } `json:"services"` } if err := json.NewDecoder(resp.Body).Decode(&out); err != nil { t.Fatal(err) } if out.Schema != 1 { t.Errorf("schema = %d, want 1", out.Schema) } if len(out.Services) != 5 { t.Fatalf("got %d services, want 5", len(out.Services)) } // DNSimple carries a write op with its consent line — the shape the web // catalog and consent chips depend on. confirmedWrite := false for _, svc := range out.Services { if svc.ID != "dnsimple" { continue } for _, op := range svc.Ops { if op.Access == "write" && op.Confirm != "" { confirmedWrite = true } } } if !confirmedWrite { t.Fatal("dnsimple must expose a write op with a confirm line") } }