fix: sync moderation refresh cache bypass
This commit is contained in:
parent
3dd9c345d7
commit
6cafa40c7b
6 changed files with 187 additions and 0 deletions
|
|
@ -1,13 +1,47 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/iamxvbaba/td/clock"
|
||||
"github.com/iamxvbaba/td/tg"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"telesrv/internal/domain"
|
||||
)
|
||||
|
||||
type moderationProjectionUsers struct {
|
||||
UsersService
|
||||
freshCalls int
|
||||
}
|
||||
|
||||
func (s *moderationProjectionUsers) ByIDs(_ context.Context, _ int64, ids []int64) ([]domain.User, error) {
|
||||
return []domain.User{{ID: ids[0], FirstName: "stale"}}, nil
|
||||
}
|
||||
|
||||
func (s *moderationProjectionUsers) ByIDsAuthoritative(_ context.Context, _ int64, ids []int64) ([]domain.User, error) {
|
||||
s.freshCalls++
|
||||
return []domain.User{{ID: ids[0], FirstName: "fresh", Scam: true}}, nil
|
||||
}
|
||||
|
||||
type moderationProjectionChannels struct {
|
||||
ChannelsService
|
||||
freshCalls int
|
||||
}
|
||||
|
||||
func (s *moderationProjectionChannels) GetChannels(_ context.Context, _ int64, ids []int64) ([]domain.ChannelView, error) {
|
||||
return []domain.ChannelView{{Channel: domain.Channel{ID: ids[0], Title: "stale", Megagroup: true}}}, nil
|
||||
}
|
||||
|
||||
func (s *moderationProjectionChannels) GetChannelsAuthoritative(_ context.Context, viewerUserID int64, ids []int64) ([]domain.ChannelView, error) {
|
||||
s.freshCalls++
|
||||
return []domain.ChannelView{{
|
||||
Channel: domain.Channel{ID: ids[0], Title: "fresh", Megagroup: true, Scam: true},
|
||||
Self: domain.ChannelMember{ChannelID: ids[0], UserID: viewerUserID, Status: domain.ChannelMemberActive},
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func TestModerationProfileUpdateCarriesStandardFlagsAndPts(t *testing.T) {
|
||||
const (
|
||||
viewerID = int64(1001)
|
||||
|
|
@ -95,3 +129,28 @@ func TestChannelModerationUpdateCarriesStandardFlagsAndPts(t *testing.T) {
|
|||
t.Fatalf("channel = %T %+v", updates.Chats[0], updates.Chats[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestModerationRefreshEventsBypassServerProjectionCaches(t *testing.T) {
|
||||
users := &moderationProjectionUsers{}
|
||||
channels := &moderationProjectionChannels{}
|
||||
r := New(Config{}, Deps{Users: users, Channels: channels}, zap.NewNop(), clock.System)
|
||||
const viewerID = int64(5005)
|
||||
events := r.enrichUpdateEvents(context.Background(), viewerID, []domain.UpdateEvent{
|
||||
{
|
||||
UserID: viewerID, Type: domain.UpdateEventUserProfile,
|
||||
Peer: domain.Peer{Type: domain.PeerTypeUser, ID: 6006},
|
||||
},
|
||||
{
|
||||
UserID: viewerID, Type: domain.UpdateEventChannelState,
|
||||
Peer: domain.Peer{Type: domain.PeerTypeChannel, ID: 7007},
|
||||
},
|
||||
})
|
||||
if users.freshCalls != 1 || len(events[0].Users) != 1 ||
|
||||
events[0].Users[0].FirstName != "fresh" || !events[0].Users[0].Scam {
|
||||
t.Fatalf("authoritative user refresh = calls:%d users:%+v", users.freshCalls, events[0].Users)
|
||||
}
|
||||
if channels.freshCalls != 1 || len(events[1].Channels) != 1 ||
|
||||
events[1].Channels[0].Title != "fresh" || !events[1].Channels[0].Scam {
|
||||
t.Fatalf("authoritative channel refresh = calls:%d channels:%+v", channels.freshCalls, events[1].Channels)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue