@@ -0,0 +1,47 @@
|
||||
package usermod
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRenewVIPLevel(t *testing.T) {
|
||||
now := time.Date(2026, 8, 29, 12, 0, 0, 0, time.UTC)
|
||||
tests := []struct {
|
||||
name string
|
||||
currentExpire time.Time
|
||||
currentLevel int
|
||||
renewedLevel int
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "preserves active higher level",
|
||||
currentExpire: now.Add(24 * time.Hour),
|
||||
currentLevel: 3,
|
||||
renewedLevel: 1,
|
||||
want: 3,
|
||||
},
|
||||
{
|
||||
name: "upgrades active lower level",
|
||||
currentExpire: now.Add(24 * time.Hour),
|
||||
currentLevel: 1,
|
||||
renewedLevel: 3,
|
||||
want: 3,
|
||||
},
|
||||
{
|
||||
name: "uses renewed level after expiration",
|
||||
currentExpire: now.Add(-time.Second),
|
||||
currentLevel: 3,
|
||||
renewedLevel: 1,
|
||||
want: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := RenewVIPLevel(tt.currentExpire, now, tt.currentLevel, tt.renewedLevel); got != tt.want {
|
||||
t.Fatalf("RenewVIPLevel() = %d, want %d", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user