-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdevice_test.go
61 lines (49 loc) · 1.46 KB
/
device_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
package stream_chat
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClient_Devices(t *testing.T) {
c := initClient(t)
ctx := context.Background()
user := randomUser(t, c)
devices := []*Device{
{UserID: user.ID, ID: randomString(12), PushProvider: PushProviderFirebase},
{UserID: user.ID, ID: randomString(12), PushProvider: PushProviderAPNS},
}
for _, dev := range devices {
_, err := c.AddDevice(ctx, dev)
require.NoError(t, err, "add device")
resp, err := c.GetDevices(ctx, user.ID)
require.NoError(t, err, "get devices")
assert.True(t, deviceIDExists(resp.Devices, dev.ID), "device with ID %s was created", dev.ID)
_, err = c.DeleteDevice(ctx, user.ID, dev.ID)
require.NoError(t, err, "delete device")
}
}
func deviceIDExists(dev []*Device, id string) bool {
for _, d := range dev {
if d.ID == id {
return true
}
}
return false
}
func ExampleClient_AddDevice() {
client, _ := NewClient("XXXX", "XXXX")
ctx := context.Background()
_, _ = client.AddDevice(ctx, &Device{
ID: "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207",
UserID: "elon",
PushProvider: PushProviderAPNS,
})
}
func ExampleClient_DeleteDevice() {
client, _ := NewClient("XXXX", "XXXX")
ctx := context.Background()
deviceID := "2ffca4ad6599adc9b5202d15a5286d33c19547d472cd09de44219cda5ac30207"
userID := "elon"
_, _ = client.DeleteDevice(ctx, userID, deviceID)
}