Skip to content

Commit

Permalink
Merge pull request #49 from twitchdev/bugfix/api-test-updates
Browse files Browse the repository at this point in the history
updating api tests to cover autopagination changes fully
  • Loading branch information
lleadbet committed Apr 14, 2021
2 parents 1e38be5 + 3ba5b6c commit df96efa
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package api
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

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

if r.URL.Path == "/error" {
w.WriteHeader(http.StatusInternalServerError)
} else if r.URL.Path == "/nocontent" {
w.WriteHeader(http.StatusNoContent)
return
} else if r.URL.Path == "/cursor" {
if strings.Contains(r.URL.RawQuery, "after") {
w.Write([]byte("{}"))
return
}
w.Write([]byte("{\"data\":[],\"pagination\":{\"cursor\":\"test\"}}"))
return
}
w.Write([]byte("{}"))
}))
defer ts.Close()
Expand All @@ -39,8 +53,18 @@ func TestNewRequest(t *testing.T) {
viper.Set("accesstoken", "4567")
viper.Set("refreshtoken", "123")

NewRequest("POST", "", []string{"test=1", "test=2"}, nil, true, false)
NewRequest("POST", "", []string{"test=1", "test=2"}, nil, false, true)
// tests for normal get requests
NewRequest("GET", "", []string{"test=1", "test=2"}, nil, true, false)
NewRequest("GET", "", []string{"test=1", "test=2"}, nil, false, true)

// testing cursors autopagination
NewRequest("GET", "/cursor", []string{"test=1", "test=2"}, nil, false, true)

// testing 204 no-content apis
NewRequest("POST", "/nocontent", []string{"test=1", "test=2"}, nil, false, false)

// testing 500 errors
NewRequest("GET", "/error", []string{"test=1", "test=2"}, nil, false, true)
}

func TestValidOptions(t *testing.T) {
Expand Down

0 comments on commit df96efa

Please sign in to comment.