Files
platforms/backend/api/internal/routers/gas_test.go
2026-08-18 00:26:39 +08:00

84 lines
2.3 KiB
Go

package routers
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
func TestGasRoutesRequireAuthentication(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
RegisterGas("heqi", engine)
request := httptest.NewRequest(http.MethodGet, "/heqi/gas/v1/gas_menu", nil)
response := httptest.NewRecorder()
engine.ServeHTTP(response, request)
if response.Code == http.StatusOK {
t.Fatal("gas menu must reject anonymous requests")
}
}
func TestGasOrderRoutesDoNotExposeDownstreamActions(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
RegisterGas("heqi", engine)
routes := map[string]bool{}
for _, route := range engine.Routes() {
routes[route.Method+" "+route.Path] = true
}
for _, path := range []string{
"POST /heqi/gas/v1/gasorder_basic/:identity/delivering",
"POST /heqi/gas/v1/gasorder_basic/:identity/awaiting-confirmation",
"POST /heqi/gas/v1/gasorder_basic/:identity/complete",
} {
if routes[path] {
t.Fatalf("gas admin must not expose downstream action %s", path)
}
}
for _, path := range []string{
"POST /heqi/gas/v1/gasorder_basic/:identity/assign",
"POST /heqi/gas/v1/gasorder_basic/:identity/filling",
"POST /heqi/gas/v1/gasorder_basic/:identity/ready",
"POST /heqi/gas/v1/gasorder_basic/:identity/exception",
"POST /heqi/gas/v1/gasorder_basic/:identity/recover",
"POST /heqi/gas/v1/gasorder_basic/:identity/cancel",
} {
if !routes[path] {
t.Fatalf("missing gas order action %s", path)
}
}
}
// TestGasReadonlyDetailRoutes 验证所有标准只读资源都支持独立详情页直达。
func TestGasReadonlyDetailRoutes(t *testing.T) {
gin.SetMode(gin.TestMode)
engine := gin.New()
RegisterGas("heqi", engine)
routes := map[string]bool{}
for _, route := range engine.Routes() {
routes[route.Method+" "+route.Path] = true
}
for _, path := range []string{
"/gasorder_contract_product/:identity",
"/gasorder_contract_revision/:identity",
"/product_info/:identity",
"/wallet_basic/:identity",
"/wallet_bank/:identity",
"/payment_order/:identity",
"/wallet_record/:identity",
"/payment_refund/:identity",
"/wallet_apply_cash/:identity",
"/fin_settlement/:identity",
"/fin_reconciliation/:identity",
} {
fullPath := "GET /heqi/gas/v1" + path
if !routes[fullPath] {
t.Fatalf("missing gas detail route %s", fullPath)
}
}
}