forked from baron/baron-sso
userfront&backend test coverage 추가
This commit is contained in:
@@ -58,6 +58,34 @@ func TestErrorWithDetailsResponseShape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorResponseShape(t *testing.T) {
|
||||
app := fiber.New()
|
||||
app.Get("/test", func(c *fiber.Ctx) error {
|
||||
return Error(c, fiber.StatusUnauthorized, "invalid_session", "login required")
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/test", nil)
|
||||
resp, err := app.Test(req)
|
||||
if err != nil {
|
||||
t.Fatalf("request failed: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusUnauthorized {
|
||||
t.Fatalf("unexpected status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body := parseBody(t, resp)
|
||||
if body["error"] != "login required" {
|
||||
t.Fatalf("unexpected error value: %v", body["error"])
|
||||
}
|
||||
if body["code"] != "invalid_session" {
|
||||
t.Fatalf("unexpected code value: %v", body["code"])
|
||||
}
|
||||
if _, exists := body["details"]; exists {
|
||||
t.Fatalf("details should be omitted when nil: %#v", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusCodeMapping(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user