Skip to content

Commit 8e5dfe7

Browse files
adityaalifnRafael Marinho
andauthored
feat: Return AsyncTaskResponse for DeactivateUsers and ReactivateUsers (#339)
* Return AsyncTaskResponse for DeactivateUsers and ReactivateUsers * fix thread tests --------- Co-authored-by: Rafael Marinho <[email protected]>
1 parent 452a078 commit 8e5dfe7

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

thread_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestClient_QueryThreads(t *testing.T) {
4141

4242
thread := resp.Threads[0]
4343
assertThreadData(t, thread, ch, parentMsg, replyMsg)
44-
assertThreadParticipants(t, thread, ch.CreatedBy.ID)
44+
assertThreadParticipants(t, thread, membersID[0])
4545

4646
assert.Empty(t, resp.PagerResponse)
4747
})
@@ -51,13 +51,13 @@ func TestClient_QueryThreads(t *testing.T) {
5151
limit := 1
5252

5353
// Create a second thread
54-
parentMsg2, err := ch.SendMessage(ctx, &Message{Text: "Parent message for thread 2"}, ch.CreatedBy.ID)
54+
parentMsg2, err := ch.SendMessage(ctx, &Message{Text: "Parent message for thread 2"}, membersID[0])
5555
require.NoError(t, err, "send second parent message")
5656

5757
replyMsg2, err := ch.SendMessage(ctx, &Message{
5858
Text: "Reply message 2",
5959
ParentID: parentMsg2.Message.ID,
60-
}, ch.CreatedBy.ID)
60+
}, membersID[0])
6161
require.NoError(t, err, "send second reply message")
6262

6363
// First page query
@@ -86,7 +86,7 @@ func TestClient_QueryThreads(t *testing.T) {
8686

8787
thread := resp.Threads[0]
8888
assertThreadData(t, thread, ch, parentMsg1, replyMsg1)
89-
assertThreadParticipants(t, thread, ch.CreatedBy.ID)
89+
assertThreadParticipants(t, thread, membersID[0])
9090

9191
// Second page query
9292
query2 := &QueryThreadsRequest{
@@ -115,7 +115,7 @@ func TestClient_QueryThreads(t *testing.T) {
115115

116116
thread = resp.Threads[0]
117117
assertThreadData(t, thread, ch, parentMsg2, replyMsg2)
118-
assertThreadParticipants(t, thread, ch.CreatedBy.ID)
118+
assertThreadParticipants(t, thread, membersID[0])
119119
})
120120
}
121121

@@ -125,14 +125,14 @@ func testThreadSetup(t *testing.T, c *Client, numMembers int) ([]string, *Channe
125125
ch := initChannel(t, c, membersID...)
126126

127127
// Create a parent message
128-
parentMsg, err := ch.SendMessage(context.Background(), &Message{Text: "Parent message for thread"}, ch.CreatedBy.ID)
128+
parentMsg, err := ch.SendMessage(context.Background(), &Message{Text: "Parent message for thread"}, membersID[0])
129129
require.NoError(t, err, "send parent message")
130130

131131
// Create a thread by sending a reply
132132
replyMsg, err := ch.SendMessage(context.Background(), &Message{
133133
Text: "Reply message",
134134
ParentID: parentMsg.Message.ID,
135-
}, ch.CreatedBy.ID)
135+
}, membersID[0])
136136
require.NoError(t, err, "send reply message")
137137

138138
return membersID, ch, parentMsg, replyMsg
@@ -142,7 +142,7 @@ func testThreadSetup(t *testing.T, c *Client, numMembers int) ([]string, *Channe
142142
func assertThreadData(t *testing.T, thread ThreadResponse, ch *Channel, parentMsg, replyMsg *MessageResponse) {
143143
assert.Equal(t, ch.CID, thread.ChannelCID, "channel CID should match")
144144
assert.Equal(t, parentMsg.Message.ID, thread.ParentMessageID, "parent message ID should match")
145-
assert.Equal(t, ch.CreatedBy.ID, thread.CreatedByUserID, "created by user ID should match")
145+
assert.Equal(t, replyMsg.Message.User.ID, thread.CreatedByUserID, "created by user ID should match")
146146
assert.Equal(t, 1, thread.ReplyCount, "reply count should be 1")
147147
assert.Equal(t, 1, thread.ParticipantCount, "participant count should be 1")
148148
assert.Equal(t, parentMsg.Message.Text, thread.Title, "title should not be empty")

user.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ type deactivateUsersOptions struct {
404404
}
405405

406406
// DeactivateUsers deactivates the users with the given target user IDs.
407-
func (c *Client) DeactivateUsers(ctx context.Context, targetIDs []string, options ...DeactivateUserOptions) (*Response, error) {
407+
// It returns an AsyncTaskResponse object which contains the task ID, the status of the task can be checked with client.GetTask method.
408+
func (c *Client) DeactivateUsers(ctx context.Context, targetIDs []string, options ...DeactivateUserOptions) (*AsyncTaskResponse, error) {
408409
if len(targetIDs) == 0 {
409410
return nil, errors.New("target IDs is empty")
410411
}
@@ -418,7 +419,7 @@ func (c *Client) DeactivateUsers(ctx context.Context, targetIDs []string, option
418419

419420
p := path.Join("users", "deactivate")
420421

421-
var resp Response
422+
var resp AsyncTaskResponse
422423
err := c.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
423424
return &resp, err
424425
}
@@ -480,7 +481,8 @@ type reactivateUsersOptions struct {
480481
}
481482

482483
// ReactivateUsers reactivates deactivated users with the given target user IDs.
483-
func (c *Client) ReactivateUsers(ctx context.Context, targetIDs []string, options ...ReactivateUserOptions) (*Response, error) {
484+
// It returns an AsyncTaskResponse object which contains the task ID, the status of the task can be checked with client.GetTask method.
485+
func (c *Client) ReactivateUsers(ctx context.Context, targetIDs []string, options ...ReactivateUserOptions) (*AsyncTaskResponse, error) {
484486
if len(targetIDs) == 0 {
485487
return nil, errors.New("target IDs is empty")
486488
}
@@ -494,7 +496,7 @@ func (c *Client) ReactivateUsers(ctx context.Context, targetIDs []string, option
494496

495497
p := path.Join("users", "reactivate")
496498

497-
var resp Response
499+
var resp AsyncTaskResponse
498500
err := c.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
499501
return &resp, err
500502
}

0 commit comments

Comments
 (0)