@@ -22,17 +22,19 @@ var _ = Describe("DynamicGroupsEndpoint", func() {
2222
2323 BeforeEach (func () {
2424 httpClient = & httpclientfakes.FakeHTTPClient {}
25+ })
26+
27+ var _ = Describe ("GetGroupStatus" , func () {
2528
26- httpResponse = & http.Response {
29+ BeforeEach (func (){
30+ httpResponse = & http.Response {
2731 StatusCode : 200 ,
2832 Body : io .NopCloser (bytes .NewBufferString (
2933 `{
3034 "dynamicGroupStatus": "active"
3135 }` )),
32- }
33- })
34-
35- var _ = Describe ("GetGroupStatus" , func () {
36+ }
37+ })
3638
3739 It ("returns a group status" , func () {
3840
@@ -98,4 +100,67 @@ var _ = Describe("DynamicGroupsEndpoint", func() {
98100 Expect (err .Error ()).To (Equal ("response body is missing dynamicGroupStatus field" ))
99101 })
100102 })
103+
104+ var _ = Describe ("GetAllDynamicGroups" , func () {
105+
106+ BeforeEach (func (){
107+ httpResponse = & http.Response {
108+ StatusCode : 200 ,
109+ Body : io .NopCloser (bytes .NewBufferString (
110+ `{
111+ "data": [0,1,2,3]
112+ }` )),
113+ }
114+ })
115+
116+ It ("returns a list of dynamic groups" , func () {
117+
118+ httpClient .DoReturns (httpResponse , nil )
119+
120+ endpoint := rest .NewDynamicGroupsEndpoint (httpClient )
121+ groups , err := endpoint .GetAllDynamicGroups ()
122+
123+ Expect (err ).NotTo (HaveOccurred ())
124+ Expect (groups .GroupIDs ).To (Equal ([]int {0 , 1 , 2 , 3 }))
125+ request := httpClient .DoArgsForCall (0 )
126+ Expect (request .URL .Path ).To (Equal ("/api/dynamicgroups" ))
127+ })
128+
129+ It ("returns an error if the request cannot be send" , func () {
130+ httpClient .DoReturns (nil , errors .New ("request failed" ))
131+
132+ endpoint := rest .NewDynamicGroupsEndpoint (httpClient )
133+ _ , err := endpoint .GetAllDynamicGroups ()
134+
135+ Expect (err ).To (HaveOccurred ())
136+ Expect (err .Error ()).To (Equal ("failed to send request, request failed" ))
137+ })
138+
139+ It ("returns an error if the status code is wrong" , func () {
140+ httpResponse := & http.Response {
141+ StatusCode : 404 ,
142+ Body : io .NopCloser (bytes .NewBufferString (`{}` ))}
143+ httpClient .DoReturns (httpResponse , nil )
144+
145+ endpoint := rest .NewDynamicGroupsEndpoint (httpClient )
146+ _ , err := endpoint .GetAllDynamicGroups ()
147+
148+ Expect (err ).To (HaveOccurred ())
149+ Expect (err .Error ()).To (Equal ("received non-200 response code: 404" ))
150+ })
151+
152+ It ("returns an error if the response body is an invalid json response" , func () {
153+ httpResponse := & http.Response {
154+ StatusCode : 200 ,
155+ Body : io .NopCloser (bytes .NewBufferString (
156+ `` ))}
157+ httpClient .DoReturns (httpResponse , nil )
158+
159+ endpoint := rest .NewDynamicGroupsEndpoint (httpClient )
160+ _ , err := endpoint .GetAllDynamicGroups ()
161+
162+ Expect (err ).To (HaveOccurred ())
163+ Expect (err .Error ()).To (ContainSubstring ("response body is not containing expected json" ))
164+ })
165+ })
101166})
0 commit comments