fix: sync correct collectible username projection

This commit is contained in:
iamxvbaba 2026-08-02 19:32:18 +08:00
parent 8356989e01
commit 9041abd3d3
42 changed files with 601 additions and 758 deletions

View file

@ -129,6 +129,15 @@ func TestBusinessChatLinkRPCs(t *testing.T) {
const userID int64 = 1000000002
ctx := WithUserID(context.Background(), userID)
r, _ := newChatAutomationTestRouter(t)
r.deps.Users = mapUsersService{users: map[int64]domain.User{
userID: {ID: userID, AccessHash: 2002, FirstName: "Business", Username: "business_slot"},
}}
registry := newFakeUsernameRegistry()
registry.byPeer[domain.Peer{Type: domain.PeerTypeUser, ID: userID}] = []domain.Username{
{Username: "business_slot", Editable: true, Active: true, SortOrder: 0},
{Username: "business_collectible", Active: true, SortOrder: 1, CollectibleID: 22},
}
r.deps.Usernames = registry
created, err := r.onAccountCreateBusinessChatLink(ctx, tg.InputBusinessChatLink{
Message: "Prefilled message",
@ -156,6 +165,13 @@ func TestBusinessChatLinkRPCs(t *testing.T) {
if !ok || peer.UserID != userID || resolved.Message != "Prefilled message" {
t.Fatalf("resolved = %+v", resolved)
}
if len(resolved.Users) != 1 {
t.Fatalf("resolved users = %+v, want one", resolved.Users)
}
assertVectorOnlyUsernames(t, "resolved business chat owner", resolved.Users[0].(*tg.User), []string{"business_slot", "business_collectible"})
if registry.peerCalls != 1 || registry.batchCalls != 0 {
t.Fatalf("resolved business username reads = peer:%d batch:%d, want 1/0", registry.peerCalls, registry.batchCalls)
}
list, err = r.onAccountGetBusinessChatLinks(ctx)
if err != nil || len(list.Links) != 1 || list.Links[0].Views != 1 {
t.Fatalf("post-resolve links = %+v err=%v", list, err)