Skip to content

Commit df96efa

Browse files
authored
Merge pull request #49 from twitchdev/bugfix/api-test-updates
updating api tests to cover autopagination changes fully
2 parents 1e38be5 + 3ba5b6c commit df96efa

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

internal/api/api_test.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package api
55
import (
66
"net/http"
77
"net/http/httptest"
8+
"strings"
89
"testing"
910
"time"
1011

@@ -29,6 +30,19 @@ func TestNewRequest(t *testing.T) {
2930
a.Equal(params.ClientID, r.Header.Get("Client-ID"), "ClientID mismatch")
3031
a.Equal("Bearer "+params.Token, r.Header.Get("Authorization"), "Token mismatch")
3132

33+
if r.URL.Path == "/error" {
34+
w.WriteHeader(http.StatusInternalServerError)
35+
} else if r.URL.Path == "/nocontent" {
36+
w.WriteHeader(http.StatusNoContent)
37+
return
38+
} else if r.URL.Path == "/cursor" {
39+
if strings.Contains(r.URL.RawQuery, "after") {
40+
w.Write([]byte("{}"))
41+
return
42+
}
43+
w.Write([]byte("{\"data\":[],\"pagination\":{\"cursor\":\"test\"}}"))
44+
return
45+
}
3246
w.Write([]byte("{}"))
3347
}))
3448
defer ts.Close()
@@ -39,8 +53,18 @@ func TestNewRequest(t *testing.T) {
3953
viper.Set("accesstoken", "4567")
4054
viper.Set("refreshtoken", "123")
4155

42-
NewRequest("POST", "", []string{"test=1", "test=2"}, nil, true, false)
43-
NewRequest("POST", "", []string{"test=1", "test=2"}, nil, false, true)
56+
// tests for normal get requests
57+
NewRequest("GET", "", []string{"test=1", "test=2"}, nil, true, false)
58+
NewRequest("GET", "", []string{"test=1", "test=2"}, nil, false, true)
59+
60+
// testing cursors autopagination
61+
NewRequest("GET", "/cursor", []string{"test=1", "test=2"}, nil, false, true)
62+
63+
// testing 204 no-content apis
64+
NewRequest("POST", "/nocontent", []string{"test=1", "test=2"}, nil, false, false)
65+
66+
// testing 500 errors
67+
NewRequest("GET", "/error", []string{"test=1", "test=2"}, nil, false, true)
4468
}
4569

4670
func TestValidOptions(t *testing.T) {

0 commit comments

Comments
 (0)