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) }