fix group invitation notifications

This commit is contained in:
richjohnrambo
2026-09-11 17:34:16 +08:00
parent cfab33f45a
commit 1d433971d4
3 changed files with 42 additions and 10 deletions
+19 -1
View File
@@ -312,6 +312,7 @@ type testMailboxStore struct {
type testUserSecurityStore struct {
unreadByPrefix map[string]int
notifications []types.SystemNotification
}
type testProfilesStore struct {
@@ -1003,7 +1004,10 @@ func (s *testUserSecurityStore) SetYouthMode(_ types.TenantID, uid types.Uid, en
return &types.YouthModeSettings{UserID: uid, Enabled: enabled, PolicyVersion: policyVersion, UpdatedAt: now}, nil
}
func (s *testUserSecurityStore) CreateSystemNotification(_ types.TenantID, _ *types.SystemNotification) error {
func (s *testUserSecurityStore) CreateSystemNotification(_ types.TenantID, notification *types.SystemNotification) error {
if notification != nil {
s.notifications = append(s.notifications, *notification)
}
return nil
}
@@ -4704,13 +4708,17 @@ func TestServeIMGroupInvitationAddsNonMember(t *testing.T) {
mockStore.EXPECT().GetUidString().Return("test")
oldSubs := store.Subs
oldGroupBusiness := store.GroupBusiness
oldSecurity := store.Security
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
groupStore := &testGroupBusinessStore{}
securityStore := &testUserSecurityStore{}
store.Subs = subs
store.GroupBusiness = groupStore
store.Security = securityStore
defer func() {
store.Subs = oldSubs
store.GroupBusiness = oldGroupBusiness
store.Security = oldSecurity
}()
owner := types.Uid(42)
target := types.Uid(43)
@@ -4737,6 +4745,16 @@ func TestServeIMGroupInvitationAddsNonMember(t *testing.T) {
if len(groupStore.invitations) != 1 || groupStore.invitations[0].TargetUserID != target || groupStore.invitations[0].InvitationID != "ginv_test" {
t.Fatalf("invitation was not persisted: %#v", groupStore.invitations)
}
if len(securityStore.notifications) != 1 {
t.Fatalf("expected one target notification, got %#v", securityStore.notifications)
}
notification := securityStore.notifications[0]
if notification.UserID != target || notification.EventType != "group.invitation.created" {
t.Fatalf("unexpected notification target/type: %#v", notification)
}
if notification.Action["type"] != "group_invitation_accept" || notification.Action["invitation_id"] != "ginv_test" || notification.Action["topic"] != "grpAlpha" {
t.Fatalf("unexpected notification action: %#v", notification.Action)
}
}
func TestServeIMGroupInvitationCreatesApprovalRequest(t *testing.T) {