mirror of
https://github.com/writefreely/writefreely
synced 2024-11-24 17:43:05 +00:00
Updated unit tests to reflect handler wrapper.
This commit is contained in:
parent
2aea9560bc
commit
6823f10821
1 changed files with 16 additions and 9 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/writeas/impart"
|
||||||
"github.com/writeas/nerds/store"
|
"github.com/writeas/nerds/store"
|
||||||
"github.com/writeas/writefreely/config"
|
"github.com/writeas/writefreely/config"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -139,7 +140,7 @@ func TestViewOauthInit(t *testing.T) {
|
||||||
Config: app.Config(),
|
Config: app.Config(),
|
||||||
DB: app.DB(),
|
DB: app.DB(),
|
||||||
Store: app.SessionStore(),
|
Store: app.SessionStore(),
|
||||||
oauthClient:writeAsOauthClient{
|
oauthClient: writeAsOauthClient{
|
||||||
ClientID: app.Config().WriteAsOauth.ClientID,
|
ClientID: app.Config().WriteAsOauth.ClientID,
|
||||||
ClientSecret: app.Config().WriteAsOauth.ClientSecret,
|
ClientSecret: app.Config().WriteAsOauth.ClientSecret,
|
||||||
ExchangeLocation: app.Config().WriteAsOauth.TokenLocation,
|
ExchangeLocation: app.Config().WriteAsOauth.TokenLocation,
|
||||||
|
@ -152,9 +153,13 @@ func TestViewOauthInit(t *testing.T) {
|
||||||
req, err := http.NewRequest("GET", "/oauth/client", nil)
|
req, err := http.NewRequest("GET", "/oauth/client", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
h.viewOauthInit(nil, rr, req)
|
err = h.viewOauthInit(nil, rr, req)
|
||||||
assert.Equal(t, http.StatusTemporaryRedirect, rr.Code)
|
assert.NotNil(t, err)
|
||||||
locURI, err := url.Parse(rr.Header().Get("Location"))
|
httpErr, ok := err.(impart.HTTPError)
|
||||||
|
assert.True(t, ok)
|
||||||
|
assert.Equal(t, http.StatusTemporaryRedirect, httpErr.Status)
|
||||||
|
assert.NotEmpty(t, httpErr.Message)
|
||||||
|
locURI, err := url.Parse(httpErr.Message)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/oauth/login", locURI.Path)
|
assert.Equal(t, "/oauth/login", locURI.Path)
|
||||||
assert.Equal(t, "development", locURI.Query().Get("client_id"))
|
assert.Equal(t, "development", locURI.Query().Get("client_id"))
|
||||||
|
@ -177,7 +182,7 @@ func TestViewOauthInit(t *testing.T) {
|
||||||
Config: app.Config(),
|
Config: app.Config(),
|
||||||
DB: app.DB(),
|
DB: app.DB(),
|
||||||
Store: app.SessionStore(),
|
Store: app.SessionStore(),
|
||||||
oauthClient:writeAsOauthClient{
|
oauthClient: writeAsOauthClient{
|
||||||
ClientID: app.Config().WriteAsOauth.ClientID,
|
ClientID: app.Config().WriteAsOauth.ClientID,
|
||||||
ClientSecret: app.Config().WriteAsOauth.ClientSecret,
|
ClientSecret: app.Config().WriteAsOauth.ClientSecret,
|
||||||
ExchangeLocation: app.Config().WriteAsOauth.TokenLocation,
|
ExchangeLocation: app.Config().WriteAsOauth.TokenLocation,
|
||||||
|
@ -190,10 +195,12 @@ func TestViewOauthInit(t *testing.T) {
|
||||||
req, err := http.NewRequest("GET", "/oauth/client", nil)
|
req, err := http.NewRequest("GET", "/oauth/client", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
h.viewOauthInit(nil, rr, req)
|
err = h.viewOauthInit(nil, rr, req)
|
||||||
assert.Equal(t, http.StatusInternalServerError, rr.Code)
|
httpErr, ok := err.(impart.HTTPError)
|
||||||
expected := `{"error":"could not prepare oauth redirect url"}` + "\n"
|
assert.True(t, ok)
|
||||||
assert.Equal(t, expected, rr.Body.String())
|
assert.NotEmpty(t, httpErr.Message)
|
||||||
|
assert.Equal(t, http.StatusInternalServerError, httpErr.Status)
|
||||||
|
assert.Equal(t, "could not prepare oauth redirect url", httpErr.Message)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue