TestUpdateAndGetUserSubscriptionsFromCache proves that event-subscription resolution works entirely through the userinfocache/DB path — which is why the write-only MyClient.subscriptions field (removed in this change) was unnecessary. updateAndGetUserSubscriptions is the only consumer of a user's su
(t *testing.T)
| 13 | // subscriptions and re-reads them per event, so dropping the dead field cannot |
| 14 | // affect which events are delivered. |
| 15 | func TestUpdateAndGetUserSubscriptionsFromCache(t *testing.T) { |
| 16 | s := makeTestServer(t) |
| 17 | const token = "sub-token" |
| 18 | const userID = "sub-user" |
| 19 | |
| 20 | // Seed the cache exactly as the connect/webhook handlers do. |
| 21 | userinfocache.Set(token, Values{m: map[string]string{"Events": "Message,ReadReceipt"}}, cache.NoExpiration) |
| 22 | t.Cleanup(func() { userinfocache.Delete(token) }) |
| 23 | |
| 24 | mycli := &MyClient{userID: userID, token: token, db: s.db} |
| 25 | got, err := updateAndGetUserSubscriptions(mycli) |
| 26 | if err != nil { |
| 27 | t.Fatalf("updateAndGetUserSubscriptions returned error: %v", err) |
| 28 | } |
| 29 | |
| 30 | want := []string{"Message", "ReadReceipt"} |
| 31 | if len(got) != len(want) { |
| 32 | t.Fatalf("subscriptions = %v, want %v", got, want) |
| 33 | } |
| 34 | for i := range want { |
| 35 | if got[i] != want[i] { |
| 36 | t.Errorf("subscriptions[%d] = %q, want %q", i, got[i], want[i]) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Unsupported event names must be filtered out. |
| 41 | userinfocache.Set(token, Values{m: map[string]string{"Events": "Message,NotAReal Event"}}, cache.NoExpiration) |
| 42 | got, err = updateAndGetUserSubscriptions(mycli) |
| 43 | if err != nil { |
| 44 | t.Fatalf("second call returned error: %v", err) |
| 45 | } |
| 46 | if len(got) != 1 || got[0] != "Message" { |
| 47 | t.Errorf("unsupported events not filtered: got %v, want [Message]", got) |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected