-
Notifications
You must be signed in to change notification settings - Fork 31
/
app_test.go
158 lines (128 loc) · 3.87 KB
/
app_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
package stream_chat
import (
"context"
"log"
"testing"
"github.com/stretchr/testify/require"
)
func TestClient_GetApp(t *testing.T) {
c := initClient(t)
ctx := context.Background()
_, err := c.GetAppSettings(ctx)
require.NoError(t, err)
}
func TestClient_UpdateAppSettings(t *testing.T) {
c := initClient(t)
ctx := context.Background()
settings := NewAppSettings().
SetDisableAuth(true).
SetDisablePermissions(true)
_, err := c.UpdateAppSettings(ctx, settings)
require.NoError(t, err)
}
func TestClient_CheckAsyncModeConfig(t *testing.T) {
c := initClient(t)
ctx := context.Background()
settings := NewAppSettings().
SetAsyncModerationConfig(
AsyncModerationConfiguration{
Callback: &AsyncModerationCallback{
Mode: "CALLBACK_MODE_REST",
ServerURL: "https://example.com/gosdk",
},
Timeout: 10000,
},
)
_, err := c.UpdateAppSettings(ctx, settings)
require.NoError(t, err)
}
func TestClient_UpdateAppSettingsClearing(t *testing.T) {
c := initClient(t)
ctx := context.Background()
sqsURL := "https://example.com"
sqsKey := "some key"
sqsSecret := "some secret"
settings := NewAppSettings()
settings.SqsURL = &sqsURL
settings.SqsKey = &sqsKey
settings.SqsSecret = &sqsSecret
_, err := c.UpdateAppSettings(ctx, settings)
require.NoError(t, err)
sqsURL = ""
settings.SqsURL = &sqsURL
_, err = c.UpdateAppSettings(ctx, settings)
require.NoError(t, err)
s, err := c.GetAppSettings(ctx)
require.NoError(t, err)
require.Equal(t, *settings.SqsURL, *s.App.SqsURL)
}
func TestClient_CheckSqs(t *testing.T) {
c := initClient(t)
ctx := context.Background()
req := &CheckSQSRequest{SqsURL: "https://foo.com/bar", SqsKey: "key", SqsSecret: "secret"}
resp, err := c.CheckSqs(ctx, req)
require.NoError(t, err)
require.NotEmpty(t, resp.Error)
require.Equal(t, "error", resp.Status)
require.NotNil(t, resp.Data)
}
func TestClient_CheckSns(t *testing.T) {
c := initClient(t)
ctx := context.Background()
req := &CheckSNSRequest{SnsTopicARN: "arn:aws:sns:us-east-1:123456789012:sns-topic", SnsKey: "key", SnsSecret: "secret"}
resp, err := c.CheckSns(ctx, req)
require.NoError(t, err)
require.NotEmpty(t, resp.Error)
require.Equal(t, "error", resp.Status)
require.NotNil(t, resp.Data)
}
func TestClient_CheckPush(t *testing.T) {
c := initClient(t)
ch := initChannel(t, c)
ctx := context.Background()
user := randomUser(t, c)
msgResp, _ := ch.SendMessage(ctx, &Message{Text: "text"}, user.ID)
skipDevices := true
req := &CheckPushRequest{MessageID: msgResp.Message.ID, SkipDevices: &skipDevices, UserID: user.ID}
resp, err := c.CheckPush(ctx, req)
require.NoError(t, err)
require.Equal(t, msgResp.Message.ID, resp.RenderedMessage["message_id"])
}
// See https://getstream.io/chat/docs/app_settings_auth/ for
// more details.
func ExampleClient_UpdateAppSettings_disable_auth() {
client, err := NewClient("XXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
if err != nil {
log.Fatalf("Err: %v", err)
}
ctx := context.Background()
// disable auth checks, allows dev token usage
settings := NewAppSettings().SetDisableAuth(true)
_, err = client.UpdateAppSettings(ctx, settings)
if err != nil {
log.Fatalf("Err: %v", err)
}
// re-enable auth checks
_, err = client.UpdateAppSettings(ctx, NewAppSettings().SetDisableAuth(false))
if err != nil {
log.Fatalf("Err: %v", err)
}
}
func ExampleClient_UpdateAppSettings_disable_permission() {
client, err := NewClient("XXXX", "XXXX")
if err != nil {
log.Fatalf("Err: %v", err)
}
ctx := context.Background()
// disable permission checkse
settings := NewAppSettings().SetDisablePermissions(true)
_, err = client.UpdateAppSettings(ctx, settings)
if err != nil {
log.Fatalf("Err: %v", err)
}
// re-enable permission checks
_, err = client.UpdateAppSettings(ctx, NewAppSettings().SetDisablePermissions(false))
if err != nil {
log.Fatalf("Err: %v", err)
}
}