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