refactor: [shitty claude AI first try] restructure server and user services, add new test cases, and improve error handling
This commit is contained in:
48
internal/server/server_test.go
Normal file
48
internal/server/server_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.logidex.ru/fakz9/logidex-id/internal/config"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewFiberApp(t *testing.T) {
|
||||
cfg := config.Config{}
|
||||
cfg.App.Port = 8080
|
||||
|
||||
app := NewFiberApp(cfg)
|
||||
|
||||
assert.NotNil(t, app)
|
||||
|
||||
// Test health check endpoint
|
||||
req := httptest.NewRequest("GET", "/health", nil)
|
||||
resp, err := app.Test(req)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 200, resp.StatusCode)
|
||||
}
|
||||
|
||||
func TestNewAPIRouter(t *testing.T) {
|
||||
cfg := config.Config{}
|
||||
cfg.App.Port = 8080
|
||||
|
||||
app := NewFiberApp(cfg)
|
||||
router := NewAPIRouter(app)
|
||||
|
||||
assert.NotNil(t, router)
|
||||
|
||||
// Test that we can add routes to the router
|
||||
router.Get("/test", func(c *fiber.Ctx) error {
|
||||
return c.JSON(map[string]string{"message": "test"})
|
||||
})
|
||||
|
||||
// Test the route works
|
||||
req := httptest.NewRequest("GET", "/api/test", nil)
|
||||
resp, err := app.Test(req)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 200, resp.StatusCode)
|
||||
}
|
||||
Reference in New Issue
Block a user