-
Notifications
You must be signed in to change notification settings - Fork 4
/
members_api_test.go
139 lines (124 loc) · 2.92 KB
/
members_api_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
package groupme
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/gorilla/mux"
"github.com/stretchr/testify/suite"
)
type MembersAPISuite struct{ APISuite }
func (s *MembersAPISuite) SetupSuite() {
s.handler = membersTestRouter()
s.setupSuite()
}
func (s *MembersAPISuite) TestMembersAdd() {
_, err := s.client.AddMembers(
context.Background(),
"1",
&Member{Nickname: "test"},
)
s.Require().NoError(err)
}
func (s *MembersAPISuite) TestMembersResults() {
_, err := s.client.AddMembersResults(context.Background(), "1", "123")
s.Require().NoError(err)
}
func (s *MembersAPISuite) TestMembersRemove() {
err := s.client.RemoveMember(context.Background(), "1", "123")
s.Require().NoError(err)
}
func (s *MembersAPISuite) TestMembersUpdate() {
_, err := s.client.UpdateMember(context.Background(), "1", "nickname")
s.Require().NoError(err)
}
func TestMembersAPISuite(t *testing.T) {
suite.Run(t, new(MembersAPISuite))
}
func membersTestRouter() *mux.Router {
router := mux.NewRouter().Queries("token", "").Subrouter()
// Add
router.Path("/groups/{id:[0-9]+}/members/add").
Methods("POST").
Name("AddMembers").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(202)
fmt.Fprint(w, `{
"response": {
"results_id": "GUID"
},
"meta": {
"code": 202,
"errors": []
}
}`)
})
// Results
router.Path("/groups/{id:[0-9]+}/members/results/{result_id}").
Methods("GET").
Name("AddMembersResults").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
fmt.Fprint(w, `{
"response": {
"members": [
{
"id": "1000",
"user_id": "10000",
"nickname": "John",
"muted": false,
"image_url": "https://i.groupme.com/AVATAR",
"autokicked": false,
"app_installed": true,
"guid": "GUID-1"
},
{
"id": "2000",
"user_id": "20000",
"nickname": "Anne",
"muted": false,
"image_url": "https://i.groupme.com/AVATAR",
"autokicked": false,
"app_installed": true,
"guid": "GUID-2"
}
]
},
"meta": {
"code": 200,
"errors": []
}
}`)
})
// Remove
router.Path("/groups/{id:[0-9]+}/members/{membership_id}/remove").
Methods("POST").
Name("RemoveMember").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
})
// Update
router.Path("/groups/{id:[0-9]+}/memberships/update").
Methods("POST").
Name("UpdateMember").
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
fmt.Fprint(w, `{
"response": {
"id": "MEMBERSHIP ID",
"user_id": "USER ID",
"nickname": "NEW NICKNAME",
"muted": false,
"image_url": "AVATAR URL",
"autokicked": false,
"app_installed": true
},
"meta": {
"code": 200,
"errors": []
}
}`)
})
/*// Return test router //*/
return router
}