Skip to content

Commit

Permalink
chore: test to ensure BadRequest status when required QueryParam is n…
Browse files Browse the repository at this point in the history
…ot supplied
  • Loading branch information
dylanhitt authored and EwenQuim committed Oct 31, 2024
1 parent 400389a commit 3b76bec
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ctx_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,22 @@ func TestParam(t *testing.T) {
require.Equal(t, http.StatusOK, w.Code)
require.Equal(t, "hey18true", w.Body.String())
})

})

t.Run("Should enforce Required", func(t *testing.T) {
s := fuego.NewServer()

fuego.Get(s, "/test", func(c fuego.ContextNoBody) (string, error) {
name := c.QueryParam("name")
return name, nil
},
option.Query("name", "Name", param.Required(), param.Example("example1", "you")),
)
r := httptest.NewRequest("GET", "/test", nil)
w := httptest.NewRecorder()
s.Mux.ServeHTTP(w, r)
require.Equal(t, http.StatusBadRequest, w.Code)
require.Contains(t, w.Body.String(), "name is a required query param")
})
}

0 comments on commit 3b76bec

Please sign in to comment.