Adds GET and PUT /marketing/loyalty-settings and GET /marketing/loyalty-settings/history (docs/prd-point-coin.md F2, PC-302). The settings are the point value, the exchange rate, transfer limits and the stored expiry settings. PUT merges the body like the outlet settings and is limited to loyalty managers. Every response carries the impact of the change on the balances in circulation: outstanding EnakPoint and EnakCoin, their rupiah value, and the coins exchanged into points, before and after. With ?dry_run=true nothing is saved and the response lists the keys that would change, for the warning shown before saving. Saving records each change in loyalty_setting_changes with who made it; history can be filtered to one outlet. Changing the value leaves what was already written alone. The diff behind saving and previewing is shared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLoyaltyCashbackPercent(t *testing.T) {
|
|
assert.Equal(t, 1.0, LoyaltyCashbackPercent(1, 1, 100))
|
|
assert.Equal(t, 0.1, LoyaltyCashbackPercent(1, 1, 1000))
|
|
assert.Equal(t, 0.33, LoyaltyCashbackPercent(1, 1, 300), "rounded to two decimals")
|
|
assert.Equal(t, 0.67, LoyaltyCashbackPercent(2, 1, 300), "rounded, not cut")
|
|
assert.Equal(t, 0.0, LoyaltyCashbackPercent(1, 1, 0))
|
|
}
|
|
|
|
func TestNewLoyaltySettingsImpact(t *testing.T) {
|
|
before := OrganizationLoyaltySettings{PointValue: 1, Exchange: LoyaltyExchangeSettings{CoinAmount: 1, PointAmount: 1}}
|
|
after := OrganizationLoyaltySettings{PointValue: 100, Exchange: LoyaltyExchangeSettings{CoinAmount: 10, PointAmount: 1}}
|
|
|
|
got := NewLoyaltySettingsImpact(50000, 105, before, after)
|
|
assert.Equal(t, LoyaltySettingsImpact{
|
|
OutstandingPoints: 50000, OutstandingCoins: 105,
|
|
PointValueBefore: 1, PointValueAfter: 100,
|
|
PointRupiahBefore: 50000, PointRupiahAfter: 5000000,
|
|
CoinsAsPointsBefore: 105, CoinsAsPointsAfter: 10, // floor(105 / 10)
|
|
CoinRupiahBefore: 105, CoinRupiahAfter: 1000,
|
|
}, got)
|
|
|
|
same := NewLoyaltySettingsImpact(10, 10, before, before)
|
|
assert.Equal(t, same.PointRupiahBefore, same.PointRupiahAfter)
|
|
}
|