forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_test.go
196 lines (141 loc) · 4.38 KB
/
user_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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package stream_chat // nolint: golint
import (
"log"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClient_BanUser(t *testing.T) {
}
func TestClient_DeactivateUser(t *testing.T) {
}
func TestClient_DeleteUser(t *testing.T) {
}
func TestClient_ExportUser(t *testing.T) {}
func TestClient_FlagUser(t *testing.T) {
}
func TestClient_MuteUser(t *testing.T) {
c := initClient(t)
initChannel(t, c)
user := randomUser()
err := c.MuteUser(user.ID, serverUser.ID)
mustNoError(t, err, "mute user")
users, err := c.QueryUsers(&QueryOption{
Filter: map[string]interface{}{
"id": map[string]string{"$eq": serverUser.ID},
}})
mustNoError(t, err, "query users")
assert.Lenf(t, users[0].Mutes, 1, "user mutes exists: %+v", users[0])
mute := users[0].Mutes[0]
assert.NotEmpty(t, mute.User, "mute has user")
assert.NotEmpty(t, mute.Target, "mute has target")
}
func TestClient_MuteUsers(t *testing.T) {
c := initClient(t)
initChannel(t, c)
users := []string{randomUser().ID, randomUser().ID}
err := c.MuteUsers(users, serverUser.ID)
mustNoError(t, err, "mute user")
}
func TestClient_UnBanUser(t *testing.T) {
}
func TestClient_UnFlagUser(t *testing.T) {
}
func TestClient_UnmuteUser(t *testing.T) {
c := initClient(t)
err := c.UnmuteUser(randomUser().ID, serverUser.ID)
assert.NoError(t, err)
}
func TestClient_UnmuteUsers(t *testing.T) {
c := initClient(t)
users := []string{randomUser().ID, randomUser().ID}
err := c.UnmuteUsers(users, serverUser.ID)
assert.NoError(t, err, "unmute users")
}
func TestClient_UpdateUsers(t *testing.T) {
c := initClient(t)
user := randomUser()
resp, err := c.UpdateUsers(user)
mustNoError(t, err, "update users")
assert.Contains(t, resp, user.ID)
assert.NotEmpty(t, resp[user.ID].CreatedAt)
assert.NotEmpty(t, resp[user.ID].UpdatedAt)
}
func TestClient_PartialUpdateUsers(t *testing.T) {
c := initClient(t)
user := randomUser()
update := PartialUserUpdate{
ID: user.ID,
Set: map[string]interface{}{
"test": map[string]interface{}{
"passed": true,
},
},
}
got, err := c.PartialUpdateUsers([]PartialUserUpdate{update})
mustNoError(t, err, "partial update user")
assert.Contains(t, got, user.ID)
assert.Contains(t, got[user.ID].ExtraData, "test", "extra data contains", got[user.ID].ExtraData)
assert.Equal(t, got[user.ID].ExtraData["test"], map[string]interface{}{
"passed": true,
})
update = PartialUserUpdate{
ID: user.ID,
Unset: []string{"test.passed"},
}
got, err = c.PartialUpdateUsers([]PartialUserUpdate{update})
mustNoError(t, err, "partial update user")
assert.Contains(t, got, user.ID)
assert.Contains(t, got[user.ID].ExtraData, "test", "extra data contains", got[user.ID].ExtraData)
assert.Empty(t, got[user.ID].ExtraData["test"], "extra data field removed")
}
func ExampleClient_UpdateUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
_, err := client.UpdateUser(&User{
ID: "tommaso",
Name: "Tommaso",
Role: "Admin",
})
if err != nil {
log.Fatalf("Err: %v", err)
}
}
func ExampleClient_ExportUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
user, _ := client.ExportUser("userID", nil)
log.Printf("%#v", user)
}
func ExampleClient_DeactivateUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
_ = client.DeactivateUser("userID", nil)
}
func ExampleClient_ReactivateUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
_ = client.ReactivateUser("userID", nil)
}
func ExampleClient_DeleteUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
_ = client.DeleteUser("userID", nil)
}
func ExampleClient_DeleteUser_hard() {
client, _ := NewClient("XXXX", []byte("XXXX"))
options := map[string][]string{
"mark_messages_deleted": {"true"},
"hard_delete": {"true"},
}
_ = client.DeleteUser("userID", options)
}
func ExampleClient_BanUser() {
client, _ := NewClient("XXXX", []byte("XXXX"))
// ban a user for 60 minutes from all channel
_ = client.BanUser("eviluser", "modUser",
map[string]interface{}{"timeout": 60, "reason": "Banned for one hour"})
// ban a user from the livestream:fortnite channel
channel := client.Channel("livestream", "fortnite")
_ = channel.BanUser("eviluser", "modUser",
map[string]interface{}{"reason": "Profanity is not allowed here"})
// remove ban from channel
channel = client.Channel("livestream", "fortnite")
_ = channel.UnBanUser("eviluser", nil)
// remove global ban
_ = client.UnBanUser("eviluser", nil)
}