-
Notifications
You must be signed in to change notification settings - Fork 31
/
async_tasks_test.go
126 lines (100 loc) · 3.01 KB
/
async_tasks_test.go
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
package stream_chat
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestClient_DeleteChannels(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
ctx := context.Background()
user := randomUser(t, c)
msg := &Message{Text: "test message"}
_, err := ch.SendMessage(ctx, msg, user.ID, MessageSkipPush)
require.NoError(t, err, "send message")
// should fail without CIDs in parameter
_, err = c.DeleteChannels(ctx, []string{}, true)
require.Error(t, err)
resp1, err := c.DeleteChannels(ctx, []string{ch.CID}, true)
require.NoError(t, err)
require.NotEmpty(t, resp1.TaskID)
for i := 0; i < 10; i++ {
resp2, err := c.GetTask(ctx, resp1.TaskID)
require.NoError(t, err)
require.Equal(t, resp1.TaskID, resp2.TaskID)
if resp2.Status == TaskStatusCompleted {
require.Equal(t, map[string]interface{}{"status": "ok"}, resp2.Result[ch.CID])
return
}
time.Sleep(time.Second)
}
}
func TestClient_DeleteUsers(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
ctx := context.Background()
user := randomUser(t, c)
msg := &Message{Text: "test message"}
_, err := ch.SendMessage(ctx, msg, user.ID, MessageSkipPush)
require.NoError(t, err, "send message")
// should fail without userIDs in parameter
_, err = c.DeleteUsers(ctx, []string{}, DeleteUserOptions{
User: SoftDelete,
Messages: HardDelete,
})
require.Error(t, err)
resp1, err := c.DeleteUsers(ctx, []string{user.ID}, DeleteUserOptions{
User: SoftDelete,
Messages: HardDelete,
})
require.NoError(t, err)
require.NotEmpty(t, resp1.TaskID)
for i := 0; i < 10; i++ {
resp2, err := c.GetTask(ctx, resp1.TaskID)
require.NoError(t, err)
require.Equal(t, resp1.TaskID, resp2.TaskID)
if resp2.Status == TaskStatusCompleted {
require.Equal(t, map[string]interface{}{"status": "ok"}, resp2.Result[user.ID])
return
}
time.Sleep(time.Second)
}
require.True(t, false, "task did not succeed")
}
func TestClient_ExportChannels(t *testing.T) {
c := initClient(t)
ch1 := initChannel(t, c)
ch2 := initChannel(t, c)
ctx := context.Background()
t.Run("Return error if there are 0 channels", func(t *testing.T) {
_, err := c.ExportChannels(ctx, nil, nil)
require.Error(t, err)
})
t.Run("Return error if exportable channel structs are incorrect", func(t *testing.T) {
expChannels := []*ExportableChannel{
{Type: "", ID: ch1.ID},
}
_, err := c.ExportChannels(ctx, expChannels, nil)
require.Error(t, err)
})
t.Run("Export channels with no error", func(t *testing.T) {
expChannels := []*ExportableChannel{
{Type: ch1.Type, ID: ch1.ID},
{Type: ch2.Type, ID: ch2.ID},
}
resp1, err := c.ExportChannels(ctx, expChannels, nil)
require.NoError(t, err)
require.NotEmpty(t, resp1.TaskID)
for i := 0; i < 10; i++ {
task, err := c.GetExportChannelsTask(ctx, resp1.TaskID)
require.NoError(t, err)
require.Equal(t, resp1.TaskID, task.TaskID)
require.NotEmpty(t, task.Status)
if task.Status == TaskStatusCompleted {
break
}
time.Sleep(time.Second)
}
})
}