forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_type_test.go
171 lines (142 loc) · 3.65 KB
/
channel_type_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
package stream_chat // nolint: golint
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func prepareChannelType(t *testing.T, c *Client) *ChannelType {
ct := NewChannelType(randomString(10))
ct, err := c.CreateChannelType(ct)
require.NoError(t, err, "create channel type")
return ct
}
func TestClient_GetChannelType(t *testing.T) {
c := initClient(t)
ct := prepareChannelType(t, c)
defer func() {
_ = c.DeleteChannelType(ct.Name)
}()
got, err := c.GetChannelType(ct.Name)
require.NoError(t, err, "get channel type")
assert.Equal(t, ct.Name, got.Name)
assert.Equal(t, len(ct.Commands), len(got.Commands))
assert.Equal(t, ct.Permissions, got.Permissions)
}
func TestClient_ListChannelTypes(t *testing.T) {
c := initClient(t)
ct := prepareChannelType(t, c)
defer func() {
_ = c.DeleteChannelType(ct.Name)
}()
got, err := c.ListChannelTypes()
require.NoError(t, err, "list channel types")
assert.Contains(t, got, ct.Name)
}
// See https://getstream.io/chat/docs/channel_features/ for more details.
func ExampleClient_CreateChannelType() {
client := &Client{}
newChannelType := &ChannelType{
// Copy the default settings.
ChannelConfig: DefaultChannelConfig,
}
newChannelType.Name = "public"
newChannelType.Mutes = false
newChannelType.Reactions = false
newChannelType.Permissions = append(newChannelType.Permissions,
&Permission{
Name: "Allow reads for all",
Priority: 999,
Resources: []string{"ReadChannel", "CreateMessage"},
Action: "Allow",
},
&Permission{
Name: "Deny all",
Priority: 1,
Resources: []string{"*"},
Action: "Deny",
},
)
_, _ = client.CreateChannelType(newChannelType)
}
func ExampleClient_ListChannelTypes() {
client := &Client{}
_, _ = client.ListChannelTypes()
}
func ExampleClient_GetChannelType() {
client := &Client{}
_, _ = client.GetChannelType("public")
}
func ExampleClient_UpdateChannelType() {
client := &Client{}
_ = client.UpdateChannelType("public", map[string]interface{}{
"permissions": []map[string]interface{}{
{
"name": "Allow reads for all",
"priority": 999,
"resources": []string{"ReadChannel", "CreateMessage"},
"role": "*",
"action": "Allow",
},
{
"name": "Deny all",
"priority": 1,
"resources": []string{"*"},
"role": "*",
"action": "Deny",
},
},
"replies": false,
"commands": []string{"all"},
})
}
func ExampleClient_UpdateChannelType_bool() {
client := &Client{}
_ = client.UpdateChannelType("public", map[string]interface{}{
"typing_events": false,
"read_events": true,
"connect_events": true,
"search": false,
"reactions": true,
"replies": false,
"mutes": true,
})
}
func ExampleClient_UpdateChannelType_other() {
client := &Client{}
_ = client.UpdateChannelType(
"public",
map[string]interface{}{
"automod": "disabled",
"message_retention": "7",
"max_message_length": 140,
"commands": []interface{}{"ban", "unban"},
},
)
}
func ExampleClient_UpdateChannelType_permissions() {
client := &Client{}
_ = client.UpdateChannelType(
"public",
map[string]interface{}{
"permissions": []map[string]interface{}{
{
"name": "Allow reads for all",
"priority": 999,
"resources": []string{"ReadChannel", "CreateMessage"},
"role": "*",
"action": "Allow",
},
{
"name": "Deny all",
"priority": 1,
"resources": []string{"*"},
"action": "Deny",
},
},
},
)
}
func ExampleClient_DeleteChannelType() {
client := &Client{}
_ = client.DeleteChannelType("public")
}