Adds GET /customer/wallet/exchange/preview?coins= and POST /customer/wallet/exchange (docs/prd-point-coin.md F4, K3, PC-401). The customer exchanges a multiple of the organization's coin_amount and gets (coins / coin_amount) x point_amount EnakPoint, approved by their PIN (K8). A malformed amount is refused before the PIN is checked, so it costs no attempt. In one transaction the wallet is locked, EXCHANGE_OUT takes the EnakCoin in K9 order and EXCHANGE_IN adds the EnakPoint; the two rows share a group, point at each other and both freeze the rate in their metadata. The EnakPoint are split over the EnakCoin lots they came from, each part keeping its lot's expiry and pointing back at it, so exchanging cannot extend a balance's life. The split takes floor(coins so far x rate) per lot, which adds up exactly because the total is a multiple of coin_amount. EnakPoint have no validity of their own until the expiry model is decided (N4), so the EnakCoin lot is for now the only bound. The Idempotency-Key header (or X-Idempotency-Key) is required. A retry with the same key is recognised under the wallet lock and replayed with the ids and rate the first attempt froze, even if the rate has changed since; the same key for another amount is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.8 KiB
Go
54 lines
1.8 KiB
Go
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",
|
|
"GET /api/v1/outlets/:outlet_id/loyalty-settings",
|
|
"PUT /api/v1/outlets/:outlet_id/loyalty-settings",
|
|
"GET /api/v1/marketing/loyalty-settings",
|
|
"PUT /api/v1/marketing/loyalty-settings",
|
|
"GET /api/v1/marketing/loyalty-settings/history",
|
|
"POST /api/v1/customer/wallet/payment-code",
|
|
"GET /api/v1/customer/wallet/exchange/preview",
|
|
"POST /api/v1/customer/wallet/exchange",
|
|
"GET /api/v1/orders/:id/point-payment/preview",
|
|
"POST /api/v1/customer/orders/:id/pay-with-points",
|
|
"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",
|
|
} {
|
|
assert.True(t, registered[want], want)
|
|
}
|
|
}
|