forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_test.go
104 lines (78 loc) · 2.07 KB
/
command_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
package stream_chat // nolint: golint
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func prepareCommand(t *testing.T, c *Client) *Command {
cmd := &Command{
Name: randomString(10),
Description: "test command",
}
cmd, err := c.CreateCommand(cmd)
require.NoError(t, err, "create command")
return cmd
}
func TestClient_GetCommand(t *testing.T) {
c := initClient(t)
cmd := prepareCommand(t, c)
defer func() {
_ = c.DeleteCommand(cmd.Name)
}()
got, err := c.GetCommand(cmd.Name)
require.NoError(t, err, "get command")
assert.Equal(t, cmd.Name, got.Name)
assert.Equal(t, cmd.Description, got.Description)
}
func TestClient_ListCommands(t *testing.T) {
c := initClient(t)
cmd := prepareCommand(t, c)
defer func() {
_ = c.DeleteCommand(cmd.Name)
}()
got, err := c.ListCommands()
require.NoError(t, err, "list commands")
assert.Contains(t, got, cmd)
}
func TestClient_UpdateCommand(t *testing.T) {
c := initClient(t)
cmd := prepareCommand(t, c)
defer func() {
_ = c.DeleteCommand(cmd.Name)
}()
got, err := c.UpdateCommand(cmd.Name, map[string]interface{}{
"description": "new description",
})
require.NoError(t, err, "update command")
assert.Equal(t, cmd.Name, got.Name)
assert.Equal(t, "new description", got.Description)
}
// See https://getstream.io/chat/docs/custom_commands/ for more details.
func ExampleClient_CreateCommand() {
client := &Client{}
newCommand := &Command{
Name: "my-command",
Description: "my command",
Args: "[@username]",
Set: "custom_cmd_set",
}
_, _ = client.CreateCommand(newCommand)
}
func ExampleClient_ListCommands() {
client := &Client{}
_, _ = client.ListCommands()
}
func ExampleClient_GetCommand() {
client := &Client{}
_, _ = client.GetCommand("my-command")
}
func ExampleClient_UpdateCommand() {
client := &Client{}
_, _ = client.UpdateCommand("my-command", map[string]interface{}{
"description": "updated description",
})
}
func ExampleClient_DeleteCommand() {
client := &Client{}
_ = client.DeleteCommand("my-command")
}