Massad/gin-boilerplate

Doesnt hit the create article endpoint

h4ck3rk3y opened this issue · 3 comments

/**
* TestCreateArticleUnauthorized
* Test getting the article with unauthorized user (wrong or expired access_token)
*
* Must return response code 401
*/
func TestCreateArticleUnauthorized(t *testing.T) {
testRouter := SetupRouter()
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/article/%d", articleID), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer: %s", "abc123"))
if err != nil {
fmt.Println(err)
}
resp := httptest.NewRecorder()
testRouter.ServeHTTP(resp, req)
assert.Equal(t, resp.Code, http.StatusUnauthorized)
}

Screen Shot 2020-05-24 at 3 05 08 PM

It does reach it, can you please explain more?

Oh sorry I was a bit confused because of the name TestCreateArticleUnauthorized. I was expecting a POST request to the /v1/article endpoint with an invalid token. This is a Get request though. TestGetArticleUnauthorized might be a better name?

You are absolutely correct! At first it was for "Creation" but then changed to "Get" because doesn't make sense to validate it post with body request... GET is less code.

Changed it here 38835a5