Adds GET and PUT /outlets/:id/loyalty-settings (docs/prd-point-coin.md F1, PC-201) on top of the typed settings processor. The response shows every setting with its default when unset, the organization's point value, and the effective EnakPoint cashback (earn_value × point_value / earn_per_amount), so an owner cannot misread the scale. PUT applies the body on top of the current settings: fields left out keep their value, null clears an optional limit, and unknown fields are refused so a typo cannot be ignored silently. The read-only fields of the GET response are accepted and ignored, so a client can send back what it received. It returns the keys that changed. Values outside the F1 bounds answer 400, and an outlet of another organization 404. RequireAdminOrManager also lets the purchasing role through, so loyalty settings and the manual wallet adjustment from PC-107 now use a stricter RequireLoyaltyManager (superadmin, admin, manager, owner). Adds a test that registers every route, since gin panics at startup when two routes name the same path parameter differently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.2 KiB
Go
39 lines
1.2 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",
|
|
} {
|
|
assert.True(t, registered[want], want)
|
|
}
|
|
}
|