42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package routes
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/handler"
|
|
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRegisterAdminRoutes_OmitsDeprecatedMockEndpoints(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
engine := gin.New()
|
|
v1 := engine.Group("/api/v1")
|
|
adminAuth := middleware.AdminAuthMiddleware(func(c *gin.Context) {
|
|
c.Next()
|
|
})
|
|
|
|
RegisterAdminRoutes(v1, &handler.Handlers{
|
|
Admin: &handler.AdminHandlers{},
|
|
}, adminAuth)
|
|
|
|
routesByMethodAndPath := make(map[string]struct{})
|
|
for _, route := range engine.Routes() {
|
|
routesByMethodAndPath[route.Method+" "+route.Path] = struct{}{}
|
|
}
|
|
|
|
deprecatedRoutes := []string{
|
|
"GET /api/v1/admin/dashboard/realtime",
|
|
"GET /api/v1/admin/users/:id/usage",
|
|
"GET /api/v1/admin/proxies/:id/stats",
|
|
"GET /api/v1/admin/redeem-codes/stats",
|
|
}
|
|
|
|
for _, route := range deprecatedRoutes {
|
|
_, exists := routesByMethodAndPath[route]
|
|
require.Falsef(t, exists, "deprecated mock route should not be registered: %s", route)
|
|
}
|
|
}
|