-
Notifications
You must be signed in to change notification settings - Fork 201
feat(slack): add support for thread replies and message updates (#187) #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,171 @@ func TestThreadedClient(t *testing.T) { | |
| ts2 string = "2" | ||
| ) | ||
|
|
||
| tests := map[string]struct { | ||
| threadTSs timestampMap | ||
| groupingKey string | ||
| policy DeliveryPolicy | ||
| wantPostType1 gomock.Matcher | ||
| wantPostType2 gomock.Matcher | ||
| wantthreadTSs timestampMap | ||
| }{ | ||
| "Post, basic": { | ||
| threadTSs: timestampMap{}, | ||
| groupingKey: "", | ||
| policy: Post, | ||
| wantPostType1: EqChatPost(), | ||
| wantthreadTSs: timestampMap{}, | ||
| }, | ||
| "Post, no parent, with grouping": { | ||
| threadTSs: timestampMap{}, | ||
| groupingKey: groupingKey, | ||
| policy: Post, | ||
| wantPostType1: EqChatPost(), | ||
| wantthreadTSs: timestampMap{channel: {groupingKey: ts1}}, | ||
| }, | ||
| "Post, with parent, with grouping": { | ||
| threadTSs: timestampMap{channel: {groupingKey: ts2}}, | ||
| groupingKey: groupingKey, | ||
| policy: Post, | ||
| wantPostType1: EqChatPost(), | ||
| wantthreadTSs: timestampMap{channel: {groupingKey: ts2}}, | ||
| }, | ||
| "PostAndUpdate, no parent. First post should not be updated": { | ||
| threadTSs: timestampMap{}, | ||
| groupingKey: groupingKey, | ||
| policy: PostAndUpdate, | ||
| wantPostType1: EqChatPost(), | ||
| wantthreadTSs: timestampMap{channel: {groupingKey: ts1}}, | ||
| }, | ||
| "PostAndUpdate, with parent. First post should be updated": { | ||
| threadTSs: timestampMap{channel: {groupingKey: ts2}}, | ||
| groupingKey: groupingKey, | ||
| policy: PostAndUpdate, | ||
| wantPostType1: EqChatPost(), | ||
| wantPostType2: EqChatUpdate(), | ||
| wantthreadTSs: timestampMap{channel: {groupingKey: ts2}}, | ||
| }, | ||
| "Update, no parent. Only call should be post": { | ||
| threadTSs: timestampMap{}, | ||
| groupingKey: groupingKey, | ||
| policy: Update, | ||
| wantPostType1: EqChatPost(), | ||
| wantthreadTSs: timestampMap{channel: {groupingKey: ts1}}, | ||
| }, | ||
| "Update, with parent. Only call should be update": { | ||
| threadTSs: timestampMap{channel: {groupingKey: ts2}}, | ||
| groupingKey: groupingKey, | ||
| policy: Update, | ||
| wantPostType1: EqChatUpdate(), | ||
| wantthreadTSs: timestampMap{channel: {groupingKey: ts2}}, | ||
| }, | ||
| } | ||
|
|
||
| // Test the existing behavior with empty threadTS and updateTS | ||
| for name, tc := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
| m := mocks.NewMockSlackClient(ctrl) | ||
|
|
||
| m.EXPECT(). | ||
| SendMessageContext(gomock.Any(), gomock.Eq(channel), tc.wantPostType1). | ||
| Return(channelID, ts1, "", nil) | ||
|
|
||
| if tc.wantPostType2 != nil { | ||
| m.EXPECT(). | ||
| SendMessageContext(gomock.Any(), gomock.Eq(channelID), tc.wantPostType2) | ||
| } | ||
|
|
||
| client := NewThreadedClient( | ||
| m, | ||
| &state{ | ||
| Limiter: rate.NewLimiter(rate.Inf, 1), | ||
| ThreadTSs: tc.threadTSs, | ||
| ChannelIDs: channelMap{}, | ||
| }, | ||
| ) | ||
| err := client.SendMessage(context.TODO(), channel, tc.groupingKey, false, tc.policy, "", "", []slack.MsgOption{}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tc.wantthreadTSs, client.ThreadTSs) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestThreadedClient_ExplicitThreadTS(t *testing.T) { | ||
| const ( | ||
| channel string = "channel" | ||
| channelID string = "channel-ID" | ||
| threadTS string = "1234567890.123456" | ||
| ts1 string = "1" | ||
| ) | ||
|
|
||
| t.Run("Explicit threadTS should reply in thread", func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
| m := mocks.NewMockSlackClient(ctrl) | ||
|
|
||
| // Expect a post message with the thread_ts option | ||
| m.EXPECT(). | ||
| SendMessageContext(gomock.Any(), gomock.Eq(channel), EqChatPost()). | ||
| Return(channelID, ts1, "", nil) | ||
|
|
||
| client := NewThreadedClient( | ||
| m, | ||
| &state{ | ||
| Limiter: rate.NewLimiter(rate.Inf, 1), | ||
| ThreadTSs: timestampMap{}, | ||
| ChannelIDs: channelMap{}, | ||
| }, | ||
| ) | ||
|
|
||
| // Send message with explicit threadTS | ||
| err := client.SendMessage(context.TODO(), channel, "", false, Post, threadTS, "", []slack.MsgOption{}) | ||
| require.NoError(t, err) | ||
| }) | ||
| } | ||
|
|
||
| func TestThreadedClient_ExplicitUpdateTS(t *testing.T) { | ||
| const ( | ||
| channel string = "channel" | ||
| channelID string = "channel-ID" | ||
| updateTS string = "1234567890.123456" | ||
| ) | ||
|
|
||
| t.Run("Explicit updateTS should update specific message", func(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
| m := mocks.NewMockSlackClient(ctrl) | ||
|
|
||
| // Expect an update call with channelID | ||
| m.EXPECT(). | ||
| SendMessageContext(gomock.Any(), gomock.Eq(channelID), EqChatUpdate()). | ||
| Return("", "", "", nil) | ||
|
|
||
| client := NewThreadedClient( | ||
| m, | ||
| &state{ | ||
| Limiter: rate.NewLimiter(rate.Inf, 1), | ||
| ThreadTSs: timestampMap{}, | ||
| ChannelIDs: channelMap{channel: channelID}, | ||
| }, | ||
| ) | ||
|
|
||
| // Send message with explicit updateTS | ||
| err := client.SendMessage(context.TODO(), channel, "", false, Post, "", updateTS, []slack.MsgOption{}) | ||
| require.NoError(t, err) | ||
| }) | ||
| } | ||
|
Comment on lines
+226
to
+256
|
||
|
|
||
| func TestThreadedClient_Backward_Compatibility(t *testing.T) { | ||
| const ( | ||
| groupingKey string = "group" | ||
| channel string = "channel" | ||
| channelID string = "channel-ID" | ||
| ts1 string = "1" | ||
| ts2 string = "2" | ||
| ) | ||
|
|
||
| tests := map[string]struct { | ||
| threadTSs timestampMap | ||
| groupingKey string | ||
|
|
@@ -181,7 +346,7 @@ func TestThreadedClient(t *testing.T) { | |
| ChannelIDs: channelMap{}, | ||
| }, | ||
| ) | ||
| err := client.SendMessage(context.TODO(), channel, tc.groupingKey, false, tc.policy, []slack.MsgOption{}) | ||
| err := client.SendMessage(context.TODO(), channel, tc.groupingKey, false, tc.policy, "", "", []slack.MsgOption{}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tc.wantthreadTSs, client.ThreadTSs) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.