-
Notifications
You must be signed in to change notification settings - Fork 31
/
command_test.go
106 lines (81 loc) · 2.33 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
105
106
package stream_chat
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func prepareCommand(t *testing.T, c *Client) *Command {
t.Helper()
cmd := &Command{
Name: randomString(10),
Description: "test command",
}
ctx := context.Background()
resp, err := c.CreateCommand(ctx, cmd)
require.NoError(t, err, "create command")
t.Cleanup(func() {
_, _ = c.DeleteCommand(ctx, cmd.Name)
})
return resp.Command
}
func TestClient_GetCommand(t *testing.T) {
c := initClient(t)
cmd := prepareCommand(t, c)
ctx := context.Background()
resp, err := c.GetCommand(ctx, cmd.Name)
require.NoError(t, err, "get command")
assert.Equal(t, cmd.Name, resp.Command.Name)
assert.Equal(t, cmd.Description, resp.Command.Description)
}
func TestClient_ListCommands(t *testing.T) {
c := initClient(t)
cmd := prepareCommand(t, c)
ctx := context.Background()
resp, err := c.ListCommands(ctx)
require.NoError(t, err, "list commands")
assert.Contains(t, resp.Commands, cmd)
}
func TestClient_UpdateCommand(t *testing.T) {
c := initClient(t)
cmd := prepareCommand(t, c)
ctx := context.Background()
update := Command{Description: "new description"}
resp, err := c.UpdateCommand(ctx, cmd.Name, &update)
require.NoError(t, err, "update command")
assert.Equal(t, cmd.Name, resp.Command.Name)
assert.Equal(t, "new description", resp.Command.Description)
}
// See https://getstream.io/chat/docs/custom_commands/ for more details.
func ExampleClient_CreateCommand() {
client := &Client{}
ctx := context.Background()
newCommand := &Command{
Name: "my-command",
Description: "my command",
Args: "[@username]",
Set: "custom_cmd_set",
}
_, _ = client.CreateCommand(ctx, newCommand)
}
func ExampleClient_ListCommands() {
client := &Client{}
ctx := context.Background()
_, _ = client.ListCommands(ctx)
}
func ExampleClient_GetCommand() {
client := &Client{}
ctx := context.Background()
_, _ = client.GetCommand(ctx, "my-command")
}
func ExampleClient_UpdateCommand() {
client := &Client{}
ctx := context.Background()
update := Command{Description: "updated description"}
_, _ = client.UpdateCommand(ctx, "my-command", &update)
}
func ExampleClient_DeleteCommand() {
client := &Client{}
ctx := context.Background()
_, _ = client.DeleteCommand(ctx, "my-command")
}