first commit
This commit is contained in:
55
backend/tests/integration/integration_test.go
Normal file
55
backend/tests/integration/integration_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/noteapp/backend/internal/infrastructure/database"
|
||||
)
|
||||
|
||||
// TestDatabaseConnection tests MongoDB connection
|
||||
func TestDatabaseConnection(t *testing.T) {
|
||||
mongoURL := "mongodb://admin:password@localhost:27017/noteapp?authSource=admin"
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
db, err := database.NewDatabase(ctx, mongoURL)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to connect to database: %v", err)
|
||||
}
|
||||
defer db.Close(ctx)
|
||||
|
||||
t.Log("✓ Successfully connected to MongoDB")
|
||||
}
|
||||
|
||||
// TestAPIHealth tests the health check endpoint
|
||||
func TestAPIHealth(t *testing.T) {
|
||||
resp, err := http.Get("http://localhost:8080/health")
|
||||
if err != nil {
|
||||
t.Skipf("Skipping test - server not running: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("Expected status 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
t.Log("✓ Health check passed")
|
||||
}
|
||||
|
||||
// TestAuthenticationFlow does an integration test of auth flow
|
||||
func TestAuthenticationFlow(t *testing.T) {
|
||||
log.Println("Integration test: Authentication flow")
|
||||
log.Println("1. Register new user")
|
||||
log.Println("2. Login with credentials")
|
||||
log.Println("3. Use access token to access protected endpoint")
|
||||
log.Println("4. Refresh access token")
|
||||
log.Println("5. Logout")
|
||||
|
||||
fmt.Println("\nTo run: cd backend && go test ./tests/integration/...")
|
||||
}
|
||||
Reference in New Issue
Block a user