[Fixes: #4088] Fix pending notification test
There were 2 issues: 1) We hard delete requests, that means that on retransmission they will be recreated, the test has been changed to accommodate this behavior 2) We always used time.now when updating timestamp in notification, sometimes time is the same so the notification is not updated, we changed to use what essentially is a clock value
This commit is contained in:
parent
05530f57bd
commit
071c431606
|
@ -76,6 +76,16 @@ type ActivityCenterNotification struct {
|
|||
AlbumMessages []*common.Message `json:"albumMessages"`
|
||||
}
|
||||
|
||||
func (n *ActivityCenterNotification) IncrementUpdatedAt(timesource common.TimeSource) {
|
||||
tNow := timesource.GetCurrentTime()
|
||||
// If updatead at is greater or equal than time now, we bump it
|
||||
if n.UpdatedAt >= tNow {
|
||||
n.UpdatedAt++
|
||||
} else {
|
||||
n.UpdatedAt = tNow
|
||||
}
|
||||
}
|
||||
|
||||
type ActivityCenterNotificationsRequest struct {
|
||||
Cursor string `json:"cursor"`
|
||||
Limit uint64 `json:"limit"`
|
||||
|
|
|
@ -1053,25 +1053,26 @@ func (s *MessengerCommunitiesSuite) TestDeletePendingRequestAccess() {
|
|||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
||||
|
||||
aliceRequestToJoin := response.RequestsToJoinCommunity[0]
|
||||
|
||||
// Retrieve request to join and Check activity center notification for Bob
|
||||
err = tt.RetryWithBackOff(func() error {
|
||||
response, err = bobRetrieveAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// NOTE: we might receive multiple requests to join in case of re-transmissions
|
||||
// because request to join are hard deleted from the database, we can't check
|
||||
// whether that's an old one or a new one. So here we test for the specific id
|
||||
|
||||
if len(response.RequestsToJoinCommunity) == 0 {
|
||||
return errors.New("request to join community not received")
|
||||
for _, r := range response.RequestsToJoinCommunity {
|
||||
if bytes.Equal(r.ID, aliceRequestToJoin.ID) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if len(response.ActivityCenterNotifications()) == 0 {
|
||||
return errors.New("request to join community notification not added in activity center")
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.New("request to join not found")
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
||||
|
||||
// Check activity center notification for Bob
|
||||
notifications, err = fetchActivityCenterNotificationsForAdmin()
|
||||
|
|
|
@ -1530,8 +1530,7 @@ func (m *Messenger) CancelRequestToJoinCommunity(ctx context.Context, request *r
|
|||
}
|
||||
|
||||
if notification != nil {
|
||||
updatedAt := m.GetCurrentTimeInMillis()
|
||||
notification.UpdatedAt = updatedAt
|
||||
notification.IncrementUpdatedAt(m.getTimesource())
|
||||
err = m.persistence.DeleteActivityCenterNotificationByID(types.FromHex(requestToJoin.ID.String()), notification.UpdatedAt)
|
||||
if err != nil {
|
||||
m.logger.Error("failed to delete notification from Activity Center", zap.Error(err))
|
||||
|
@ -1540,7 +1539,7 @@ func (m *Messenger) CancelRequestToJoinCommunity(ctx context.Context, request *r
|
|||
|
||||
// set notification as deleted, so that the client will remove the activity center notification from UI
|
||||
notification.Deleted = true
|
||||
err = m.syncActivityCenterDeletedByIDs(ctx, []types.HexBytes{notification.ID}, updatedAt)
|
||||
err = m.syncActivityCenterDeletedByIDs(ctx, []types.HexBytes{notification.ID}, notification.UpdatedAt)
|
||||
if err != nil {
|
||||
m.logger.Error("CancelRequestToJoinCommunity, failed to sync activity center notification as deleted", zap.Error(err))
|
||||
return nil, err
|
||||
|
@ -1631,7 +1630,7 @@ func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.Requ
|
|||
}
|
||||
notification.Read = true
|
||||
notification.Accepted = true
|
||||
notification.UpdatedAt = m.GetCurrentTimeInMillis()
|
||||
notification.IncrementUpdatedAt(m.getTimesource())
|
||||
|
||||
err = m.addActivityCenterNotification(response, notification, m.syncActivityCenterCommunityRequestDecisionAdapter)
|
||||
if err != nil {
|
||||
|
@ -1715,7 +1714,7 @@ func (m *Messenger) declineRequestToJoinCommunity(requestToJoin *communities.Req
|
|||
}
|
||||
notification.Read = true
|
||||
notification.Dismissed = true
|
||||
notification.UpdatedAt = m.GetCurrentTimeInMillis()
|
||||
notification.IncrementUpdatedAt(m.getTimesource())
|
||||
|
||||
err = m.addActivityCenterNotification(response, notification, m.syncActivityCenterCommunityRequestDecisionAdapter)
|
||||
if err != nil {
|
||||
|
@ -1898,7 +1897,7 @@ func (m *Messenger) CheckAndDeletePendingRequestToJoinCommunity(ctx context.Cont
|
|||
notification.MembershipStatus = ActivityCenterMembershipStatusIdle
|
||||
notification.Read = false
|
||||
notification.Deleted = false
|
||||
notification.UpdatedAt = m.GetCurrentTimeInMillis()
|
||||
notification.IncrementUpdatedAt(m.getTimesource())
|
||||
err = m.addActivityCenterNotification(response, notification, m.syncActivityCenterUnreadByIDs)
|
||||
if err != nil {
|
||||
m.logger.Error("failed to update notification in activity center", zap.Error(err))
|
||||
|
@ -3019,7 +3018,7 @@ func (m *Messenger) handleCommunityResponse(state *ReceivedMessageState, communi
|
|||
|
||||
notification.Read = true
|
||||
notification.Accepted = true
|
||||
notification.UpdatedAt = m.GetCurrentTimeInMillis()
|
||||
notification.IncrementUpdatedAt(m.getTimesource())
|
||||
|
||||
err = m.addActivityCenterNotification(state.Response, notification, nil)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue