2026-09-30 10:28:40 +07:00
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
|
|
"apskel-pos-be/config"
|
|
|
|
|
"apskel-pos-be/internal/middleware"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Gin panics at startup when two routes disagree on a path parameter's name at the
|
|
|
|
|
// same position (say /outlets/:id/x next to /outlets/:outlet_id/y). Registering every
|
|
|
|
|
// route here catches that in a test instead of on deploy. Handlers are nil: nothing is
|
|
|
|
|
// served, only registered.
|
|
|
|
|
func TestAllRoutesRegister(t *testing.T) {
|
|
|
|
|
r := &Router{
|
|
|
|
|
config: &config.Config{},
|
|
|
|
|
authMiddleware: middleware.NewAuthMiddleware(nil),
|
|
|
|
|
customerAuthMiddleware: middleware.NewCustomerAuthMiddleware("test"),
|
|
|
|
|
}
|
|
|
|
|
engine := r.Init()
|
|
|
|
|
|
|
|
|
|
registered := map[string]bool{}
|
|
|
|
|
for _, route := range engine.Routes() {
|
|
|
|
|
registered[route.Method+" "+route.Path] = true
|
|
|
|
|
}
|
|
|
|
|
for _, want := range []string{
|
|
|
|
|
"GET /api/v1/customer/wallet",
|
|
|
|
|
"GET /api/v1/customer/wallet/transactions",
|
|
|
|
|
"GET /api/v1/marketing/customers/:id/wallet",
|
|
|
|
|
"POST /api/v1/marketing/customers/:id/wallet/adjust",
|
2026-09-30 12:25:17 +07:00
|
|
|
"GET /api/v1/marketing/wallet-transactions/:id/trace",
|
2026-09-30 10:28:40 +07:00
|
|
|
"GET /api/v1/outlets/:outlet_id/loyalty-settings",
|
|
|
|
|
"PUT /api/v1/outlets/:outlet_id/loyalty-settings",
|
2026-09-30 11:26:16 +07:00
|
|
|
"GET /api/v1/marketing/loyalty-settings",
|
|
|
|
|
"PUT /api/v1/marketing/loyalty-settings",
|
|
|
|
|
"GET /api/v1/marketing/loyalty-settings/history",
|
2026-09-30 11:37:20 +07:00
|
|
|
"POST /api/v1/customer/wallet/payment-code",
|
2026-09-30 12:09:53 +07:00
|
|
|
"GET /api/v1/customer/wallet/exchange/preview",
|
|
|
|
|
"POST /api/v1/customer/wallet/exchange",
|
2026-09-30 12:14:32 +07:00
|
|
|
"GET /api/v1/customer/wallet/transfer/recipient",
|
|
|
|
|
"POST /api/v1/customer/wallet/transfer",
|
2026-09-30 11:46:31 +07:00
|
|
|
"GET /api/v1/orders/:id/point-payment/preview",
|
2026-09-30 11:49:49 +07:00
|
|
|
"POST /api/v1/customer/orders/:id/pay-with-points",
|
2026-09-30 11:20:29 +07:00
|
|
|
"GET /api/v1/customer/pin/status",
|
|
|
|
|
"POST /api/v1/customer/pin/otp",
|
|
|
|
|
"POST /api/v1/customer/pin",
|
|
|
|
|
"PUT /api/v1/customer/pin",
|
|
|
|
|
"POST /api/v1/customer/pin/reset",
|
|
|
|
|
"DELETE /api/v1/marketing/customers/:id/pin",
|
|
|
|
|
"GET /api/v1/marketing/customers/:id/security-events",
|
2026-09-30 10:28:40 +07:00
|
|
|
} {
|
|
|
|
|
assert.True(t, registered[want], want)
|
|
|
|
|
}
|
|
|
|
|
}
|