fix: notify p2p message mutation on user channel
This commit is contained in:
@@ -7966,6 +7966,72 @@ func TestServeIMMessageRecallNormalizesP2PUserTopic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnqueueIMP2PMessageMutationEventsDeliversUserDirtyMarker(t *testing.T) {
|
||||
oldStore := globals.sessionStore
|
||||
defer func() { globals.sessionStore = oldStore }()
|
||||
|
||||
tenantID := types.TenantID(7)
|
||||
actor := types.Uid(42)
|
||||
peer := types.Uid(43)
|
||||
topic := actor.P2PName(peer)
|
||||
globals.sessionStore = realtimeTestSessionStore(
|
||||
realtimeTestSession("actor-session", tenantID, actor, "me"),
|
||||
realtimeTestSession("peer-session", tenantID, peer, "me"),
|
||||
)
|
||||
|
||||
if err := enqueueIMP2PMessageMutationEvents(tenantID, topic, actor, 9, 2, "message.recalled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
sid string
|
||||
uid types.Uid
|
||||
}{
|
||||
{"actor-session", actor},
|
||||
{"peer-session", peer},
|
||||
} {
|
||||
sess := globals.sessionStore.Get(tc.sid)
|
||||
select {
|
||||
case raw := <-sess.send:
|
||||
msg, ok := raw.(*ServerComMessage)
|
||||
if !ok || msg.Info == nil {
|
||||
t.Fatalf("unexpected outbound for %s: %#v", tc.sid, raw)
|
||||
}
|
||||
if msg.Info.Topic != tc.uid.UserId() || msg.Info.Event != "message.mutation" || msg.Info.What != "im" {
|
||||
t.Fatalf("unexpected mutation marker for %s: %#v", tc.sid, msg.Info)
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(msg.Info.Payload, &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if payload["topic"] != topic || payload["event"] != "message.recalled" ||
|
||||
payload["seq"].(float64) != 9 || payload["version"].(float64) != 2 {
|
||||
t.Fatalf("unexpected mutation payload for %s: %#v", tc.sid, payload)
|
||||
}
|
||||
default:
|
||||
t.Fatalf("expected mutation marker for %s", tc.sid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnqueueIMP2PMessageMutationEventsIgnoresGroupTopic(t *testing.T) {
|
||||
oldStore := globals.sessionStore
|
||||
defer func() { globals.sessionStore = oldStore }()
|
||||
|
||||
tenantID := types.TenantID(7)
|
||||
actor := types.Uid(42)
|
||||
globals.sessionStore = realtimeTestSessionStore(
|
||||
realtimeTestSession("actor-session", tenantID, actor, "me"),
|
||||
)
|
||||
|
||||
if err := enqueueIMP2PMessageMutationEvents(tenantID, "grpRecall", actor, 9, 2, "message.recalled"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(globals.sessionStore.Get("actor-session").send) != 0 {
|
||||
t.Fatal("group topic should not emit per-user mutation markers")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMMessageRevision(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
Reference in New Issue
Block a user