-
Notifications
You must be signed in to change notification settings - Fork 14
/
getstream_test.go
94 lines (78 loc) · 1.95 KB
/
getstream_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
package getstream_test
import (
"os"
getstream "github.com/GetStream/stream-go"
)
func PreTestSetup() (*getstream.Client, error) {
return doTestSetup(&getstream.Config{
APIKey: os.Getenv("STREAM_API_KEY"),
APISecret: os.Getenv("STREAM_API_SECRET"),
AppID: os.Getenv("STREAM_APP_ID"),
Location: os.Getenv("STREAM_REGION"),
TimeoutInt: 1000,
})
}
func PreTestSetupWithToken() (*getstream.Client, error) {
return doTestSetup(&getstream.Config{
APIKey: os.Getenv("STREAM_API_KEY"),
Token: os.Getenv("STREAM_API_SECRET"), // instead of APISecret
AppID: os.Getenv("STREAM_APP_ID"),
Location: os.Getenv("STREAM_REGION"),
TimeoutInt: 1000,
})
}
func doTestSetup(cfg *getstream.Config) (*getstream.Client, error) {
return getstream.New(cfg)
}
func PostTestCleanUp(
client *getstream.Client,
flats []*getstream.Activity,
notifications []*getstream.Activity,
aggregations []*getstream.Activity) error {
if len(flats) > 0 {
feed, err := client.FlatFeed("flat", "bob")
if err != nil {
return err
}
for _, activity := range flats {
err := feed.RemoveActivity(activity)
if err != nil {
return err
}
}
}
if len(notifications) > 0 {
feed, err := client.NotificationFeed("notification", "bob")
if err != nil {
return err
}
for _, activity := range notifications {
err := feed.RemoveActivity(activity)
if err != nil {
return err
}
}
}
if len(aggregations) > 0 {
feed, err := client.AggregatedFeed("aggregated", "bob")
if err != nil {
return err
}
for _, activity := range aggregations {
err := feed.RemoveActivity(activity)
if err != nil {
return err
}
}
}
return nil
}
func PostTestCleanUpFlatFeedFollows(client *getstream.Client, feeds []*getstream.FlatFeed) error {
for _, feed := range feeds {
followers, _ := feed.FollowersWithLimitAndSkip(300, 0)
for _, follower := range followers {
follower.Unfollow(client, feed)
}
}
return nil
}