tinyrelayfile
tinyrelay/internal/daemon/grasp_capabilities_test.go/

internal/daemon/grasp_capabilities_test.go raw
1package daemon
2
3import (
4 "context"
5 "encoding/json"
6 "net/http"
7 "net/http/httptest"
8 "reflect"
9 "testing"
10)
11
12func TestPrivateNIP11MatchesRuntimeGRASPCapabilities(t *testing.T) {
13 _, tenant := testTenant(t)
14 p := tenant.Policy()
15 p.Features.Grasp = true
16 p.Features.Grasp02 = true
17 p.Features.Grasp03 = true
18 p.Features.Grasp06 = true
19 p.Features.Grasp08 = true
20 p.Reads = "members"
21 if err := tenant.applyPolicy(context.Background(), p); err != nil {
22 t.Fatal(err)
23 }
24 req := httptest.NewRequest(http.MethodGet, "http://relay.test/", nil)
25 req.Header.Set("Accept", "application/nostr+json")
26 res := httptest.NewRecorder()
27 tenant.ServeHTTP(res, req)
28 var info struct {
29 Profiles []string `json:"supported_grasps"`
30 }
31 if err := json.Unmarshal(res.Body.Bytes(), &info); err != nil {
32 t.Fatal(err)
33 }
34 want := []string{"GRASP-01", "GRASP-02", "GRASP-03", "GRASP-06", "GRASP-08"}
35 if !reflect.DeepEqual(info.Profiles, want) {
36 t.Fatalf("NIP-11 profiles = %v", info.Profiles)
37 }
38 for _, capability := range tenant.Capabilities(nil) {
39 if capability.ID == "GRASP" && !reflect.DeepEqual(capability.Profiles, info.Profiles) {
40 t.Fatalf("runtime profiles = %v; NIP-11 = %v", capability.Profiles, info.Profiles)
41 }
42 }
43}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs