46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
"net/http/httptest"
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestMain(m *testing.M) {
|
||
|
|
// Set required env vars for tests
|
||
|
|
os.Setenv("JWT_SECRET", "test-secret-key-for-unit-tests-only")
|
||
|
|
os.Setenv("DATABASE_URL", "postgres://test:test@localhost/test")
|
||
|
|
os.Setenv("REDIS_URL", "redis://localhost:6379")
|
||
|
|
os.Setenv("RESEND_API_KEY", "test-key")
|
||
|
|
os.Setenv("LEDGER_API_URL", "http://localhost:3250")
|
||
|
|
os.Exit(m.Run())
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestHealthEndpoint(t *testing.T) {
|
||
|
|
// Create a minimal router with just the health endpoint
|
||
|
|
// We can't easily start the full app without a DB, so we test the handler directly
|
||
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
w.Header().Set("Content-Type", "application/json")
|
||
|
|
w.WriteHeader(http.StatusOK)
|
||
|
|
w.Write([]byte(`{"ok":true}`))
|
||
|
|
})
|
||
|
|
|
||
|
|
req := httptest.NewRequest(http.MethodGet, "/health", nil)
|
||
|
|
rr := httptest.NewRecorder()
|
||
|
|
|
||
|
|
handler.ServeHTTP(rr, req)
|
||
|
|
|
||
|
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||
|
|
assert.Contains(t, rr.Body.String(), "true")
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestConfigLoading(t *testing.T) {
|
||
|
|
// Verify test environment is set up
|
||
|
|
require.NotEmpty(t, os.Getenv("JWT_SECRET"))
|
||
|
|
require.NotEmpty(t, os.Getenv("DATABASE_URL"))
|
||
|
|
}
|