Inicial
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package server_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/techxcar/backend/internal/server"
|
||||
)
|
||||
|
||||
func TestHealthEndpoint_returnsOK(t *testing.T) {
|
||||
app := fiber.New()
|
||||
server.RegisterHealthRoutes(app)
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/v1/health", nil)
|
||||
resp, err := app.Test(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, 200, resp.StatusCode)
|
||||
|
||||
var body map[string]any
|
||||
require.NoError(t, json.NewDecoder(resp.Body).Decode(&body))
|
||||
assert.Equal(t, "ok", body["status"])
|
||||
assert.NotEmpty(t, body["version"])
|
||||
}
|
||||
|
||||
func TestHealthEndpoint_wrongMethod(t *testing.T) {
|
||||
app := fiber.New()
|
||||
server.RegisterHealthRoutes(app)
|
||||
|
||||
req := httptest.NewRequest("POST", "/api/v1/health", nil)
|
||||
resp, err := app.Test(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, 405, resp.StatusCode)
|
||||
}
|
||||
Reference in New Issue
Block a user