init commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package routes
|
||||
|
||||
const (
|
||||
UUID = "[a-zA-Z0-9_-]{11}"
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"authentication/handlers"
|
||||
"database/sql"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
httpSwagger "github.com/swaggo/http-swagger"
|
||||
)
|
||||
|
||||
func SetupRoutes(router *mux.Router, db *sql.DB) {
|
||||
authRoutes := router.PathPrefix("/v1/auth").Subrouter()
|
||||
authRoutes.HandleFunc("/login", handlers.GoogleLogin).Methods("GET")
|
||||
authRoutes.HandleFunc("/callback", handlers.GoogleCallback).Methods("GET")
|
||||
authRoutes.HandleFunc("/refresh_token", handlers.HandleTokenRefresh).Methods("GET", "POST", "OPTIONS")
|
||||
authRoutes.HandleFunc("/logout", handlers.LogoutHandler).Methods("GET")
|
||||
|
||||
// authRoutes.HandleFunc("/microsoft/login", handlers.MicrosoftLogin).Methods("GET")
|
||||
// authRoutes.HandleFunc("/microsoft/callback", handlers.MicrosoftCallback).Methods("GET")
|
||||
|
||||
router.PathPrefix("/swagger/").Handler(httpSwagger.WrapHandler)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package routes_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Note: Full integration tests for routes require handlers to be initialized with proper environment (.env file).
|
||||
// The routes package imports handlers which have init() functions that load configuration.
|
||||
// These tests document the expected route structure without triggering handler initialization.
|
||||
|
||||
func TestExpectedAuthRoutes(t *testing.T) {
|
||||
// Test documents the expected routes that SetupRoutes should configure
|
||||
expectedRoutes := []struct {
|
||||
path string
|
||||
method string
|
||||
desc string
|
||||
}{
|
||||
{"/v1/auth/login", "GET", "Google OAuth login"},
|
||||
{"/v1/auth/callback", "GET", "Google OAuth callback"},
|
||||
{"/v1/auth/refresh_token", "GET", "Refresh access token (GET)"},
|
||||
{"/v1/auth/refresh_token", "POST", "Refresh access token (POST)"},
|
||||
{"/v1/auth/refresh_token", "OPTIONS", "Refresh access token (OPTIONS)"},
|
||||
{"/v1/auth/logout", "GET", "Logout user"},
|
||||
}
|
||||
|
||||
if len(expectedRoutes) != 6 {
|
||||
t.Errorf("Expected exactly 6 auth routes, documented %d", len(expectedRoutes))
|
||||
}
|
||||
|
||||
// Verify all routes have proper structure
|
||||
for _, route := range expectedRoutes {
|
||||
if route.path == "" {
|
||||
t.Error("Route path should not be empty")
|
||||
}
|
||||
if route.method == "" {
|
||||
t.Error("Route method should not be empty")
|
||||
}
|
||||
if route.desc == "" {
|
||||
t.Error("Route description should not be empty")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpectedSwaggerRoute(t *testing.T) {
|
||||
// Test documents that swagger documentation route should be configured
|
||||
expectedSwaggerPath := "/swagger/"
|
||||
expectedDesc := "Swagger API documentation"
|
||||
|
||||
if expectedSwaggerPath != "/swagger/" {
|
||||
t.Errorf("Expected swagger path '/swagger/', got '%s'", expectedSwaggerPath)
|
||||
}
|
||||
|
||||
if expectedDesc == "" {
|
||||
t.Error("Swagger route should have description")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouteConstants(t *testing.T) {
|
||||
// Test documents route-related constants
|
||||
const (
|
||||
authPrefix = "/v1/auth"
|
||||
swaggerPrefix = "/swagger/"
|
||||
)
|
||||
|
||||
if authPrefix != "/v1/auth" {
|
||||
t.Errorf("Expected auth prefix '/v1/auth', got '%s'", authPrefix)
|
||||
}
|
||||
|
||||
if swaggerPrefix != "/swagger/" {
|
||||
t.Errorf("Expected swagger prefix '/swagger/', got '%s'", swaggerPrefix)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user