Files
platforms/backend/api/internal/routers/gas_test.go

55 lines
1.5 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)
}
}
}