yumi-cron/internal/service/recharge_reward_settlement_test.go
2026-05-21 11:15:04 +08:00

55 lines
1.8 KiB
Go

package service
import (
"testing"
"time"
)
func TestRechargeRewardCurrentPeriodStartsOnMay21ThenCalendarMonth(t *testing.T) {
location, err := time.LoadLocation("Asia/Riyadh")
if err != nil {
t.Fatalf("load location: %v", err)
}
startAt := rechargeRewardStartAt("2026-05-21", location)
beforeStart := time.Date(2026, 5, 20, 23, 59, 59, 0, location)
if _, ok := rechargeRewardCurrentPeriod(beforeStart, startAt, location); ok {
t.Fatalf("period before start should be inactive")
}
firstNow := time.Date(2026, 5, 21, 0, 0, 0, 0, location)
first, ok := rechargeRewardCurrentPeriod(firstNow, startAt, location)
if !ok {
t.Fatalf("first period should be active")
}
if first.CycleKey != "20260521" || first.RechargeDate != 202605 {
t.Fatalf("first period key/date = %s/%d", first.CycleKey, first.RechargeDate)
}
if !first.StartAt.Equal(startAt) {
t.Fatalf("first start = %s, want %s", first.StartAt, startAt)
}
if want := time.Date(2026, 6, 1, 0, 0, 0, 0, location); !first.EndAt.Equal(want) {
t.Fatalf("first end = %s, want %s", first.EndAt, want)
}
secondNow := time.Date(2026, 6, 1, 0, 0, 0, 0, location)
second, ok := rechargeRewardCurrentPeriod(secondNow, startAt, location)
if !ok {
t.Fatalf("second period should be active")
}
if second.CycleKey != "20260601" || second.RechargeDate != 202606 {
t.Fatalf("second period key/date = %s/%d", second.CycleKey, second.RechargeDate)
}
if want := time.Date(2026, 6, 1, 0, 0, 0, 0, location); !second.StartAt.Equal(want) {
t.Fatalf("second start = %s, want %s", second.StartAt, want)
}
}
func TestRechargeRewardGoldEventIDUsesCycleAndLevel(t *testing.T) {
got := rechargeRewardGoldEventID("likei", "20260601", 42, 3)
want := "recharge-reward:LIKEI:20260601:42:3"
if got != want {
t.Fatalf("event id = %q, want %q", got, want)
}
}