github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/transcripts_test.go (about) 1 package chat 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/keybase/client/go/kbun" 9 10 "github.com/keybase/client/go/protocol/chat1" 11 "github.com/keybase/client/go/protocol/keybase1" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestTranscript(t *testing.T) { 16 t.Skip("Y2K-1384") 17 runWithMemberTypes(t, func(mt chat1.ConversationMembersType) { 18 // Only run this test for imp teams 19 switch mt { 20 case chat1.ConversationMembersType_IMPTEAMNATIVE, 21 chat1.ConversationMembersType_IMPTEAMUPGRADE: 22 default: 23 return 24 } 25 26 ctc := makeChatTestContext(t, "TestTranscripts", 3) 27 defer ctc.cleanup() 28 users := ctc.users() 29 30 tc1 := ctc.world.Tcs[users[0].Username] 31 ctx := ctc.as(t, users[0]).startCtx 32 33 displayName := strings.Join([]string{ 34 users[0].Username, 35 users[1].Username, 36 users[2].Username, 37 }, ",") 38 39 ncres, err := ctc.as(t, users[0]).chatLocalHandler().NewConversationLocal(ctx, 40 chat1.NewConversationLocalArg{ 41 TlfName: displayName, 42 TopicType: chat1.TopicType_CHAT, 43 TlfVisibility: keybase1.TLFVisibility_PRIVATE, 44 MembersType: mt, 45 IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI, 46 }) 47 require.NoError(t, err) 48 49 for i := range users { 50 mustPostLocalForTest(t, ctc, users[i], ncres.Conv.Info, 51 chat1.NewMessageBodyWithText(chat1.MessageText{ 52 Body: fmt.Sprintf("hello from user %d", i), 53 })) 54 } 55 56 // Make a config for tests to ensure fetching multiple batches with 57 // pagination. 58 config := PullTranscriptConfig{ 59 messageCount: 10, 60 batchSize: 2, 61 batchCount: 5, 62 } 63 64 mctx := tc1.MetaContext().WithLogTag("REPORT") 65 res, err := PullTranscript(mctx, tc1.Context().ConvSource, 66 ncres.Conv.GetConvID().ConvIDStr(), nil, config) 67 require.NoError(t, err) 68 require.Len(t, res.Messages, 3) 69 for i := range res.Messages { 70 require.Equal(t, res.Messages[i].SenderUsername, users[2-i].Username) 71 } 72 73 mctx = tc1.MetaContext().WithLogTag("REPORT") 74 usernames := []kbun.NormalizedUsername{ 75 kbun.NewNormalizedUsername(users[0].Username), 76 kbun.NewNormalizedUsername(users[1].Username), 77 } 78 res, err = PullTranscript(mctx, tc1.Context().ConvSource, 79 ncres.Conv.GetConvID().ConvIDStr(), usernames, config) 80 require.NoError(t, err) 81 require.Len(t, res.Messages, 2) 82 // Messages from users[2] should be skipped. 83 require.Equal(t, res.Messages[0].SenderUsername, users[1].Username) 84 require.Equal(t, res.Messages[1].SenderUsername, users[0].Username) 85 }) 86 } 87 88 func TestTranscriptLimit(t *testing.T) { 89 t.Skip("Y2K-1384") 90 // Make sure the pagination is limited, so we don't end up digging for 91 // messages in a busy channel for e.g. someone who hasn't even spoken 92 // there. 93 94 runWithMemberTypes(t, func(mt chat1.ConversationMembersType) { 95 // Only run this test for imp teams 96 switch mt { 97 case chat1.ConversationMembersType_IMPTEAMNATIVE, 98 chat1.ConversationMembersType_IMPTEAMUPGRADE: 99 default: 100 return 101 } 102 103 ctc := makeChatTestContext(t, "TestTranscripts", 2) 104 defer ctc.cleanup() 105 users := ctc.users() 106 107 tc1 := ctc.world.Tcs[users[0].Username] 108 ctx := ctc.as(t, users[0]).startCtx 109 110 displayName := strings.Join([]string{ 111 users[0].Username, 112 users[1].Username, 113 }, ",") 114 115 ncres, err := ctc.as(t, users[0]).chatLocalHandler().NewConversationLocal(ctx, 116 chat1.NewConversationLocalArg{ 117 TlfName: displayName, 118 TopicType: chat1.TopicType_CHAT, 119 TlfVisibility: keybase1.TLFVisibility_PRIVATE, 120 MembersType: mt, 121 IdentifyBehavior: keybase1.TLFIdentifyBehavior_CHAT_CLI, 122 }) 123 require.NoError(t, err) 124 125 mustPostLocalForTest(t, ctc, users[1], ncres.Conv.Info, 126 chat1.NewMessageBodyWithText(chat1.MessageText{ 127 Body: "hello chat", 128 })) 129 130 for i := 0; i < 10; i++ { 131 mustPostLocalForTest(t, ctc, users[0], ncres.Conv.Info, 132 chat1.NewMessageBodyWithText(chat1.MessageText{ 133 Body: fmt.Sprintf("hello message %d", i), 134 })) 135 } 136 137 // With this config, we will not be able to dig through 10 messages 138 // from users[0] to reach message from users[1]. 139 config := PullTranscriptConfig{ 140 messageCount: 5, 141 batchSize: 2, 142 batchCount: 3, 143 } 144 145 mctx := tc1.MetaContext().WithLogTag("REPORT") 146 usernames := []kbun.NormalizedUsername{ 147 kbun.NewNormalizedUsername(users[1].Username), 148 } 149 res, err := PullTranscript(mctx, tc1.Context().ConvSource, 150 ncres.Conv.GetConvID().ConvIDStr(), usernames, config) 151 require.NoError(t, err) 152 require.Len(t, res.Messages, 0) 153 }) 154 }