Files
qitongxue-api/internal/logic/admin_level_s10_test.go
2026-09-29 10:57:01 +08:00

39 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logic
import (
"testing"
"github.com/gogf/gf/v2/os/gtime"
)
// ============================================================================
// 约定 S10 单测(纯函数,不依赖 DB)
//
// level_expire_at IS NULL/零值 = 永久有效;续费 / 手动开通**不得把永久覆写成有限期**。
// ============================================================================
func TestLevelExpireTransitionErr(t *testing.T) {
future := gtime.New("2999-01-01 00:00:00")
cases := []struct {
name string
prevPermanent bool
newExpire *gtime.Time
wantErr bool
}{
{"永久 → 永久(NULL) 放行", true, nil, false},
{"永久 → 有限期 拒绝(S10)", true, future, true},
{"有限期 → 有限期 放行", false, future, false},
{"有限期 → 永久(NULL) 放行", false, nil, false},
}
for _, c := range cases {
err := levelExpireTransitionErr(c.prevPermanent, c.newExpire)
if c.wantErr && err == nil {
t.Errorf("%s: 期望报错,实得 nil", c.name)
}
if !c.wantErr && err != nil {
t.Errorf("%s: 期望放行,实得 err=%v", c.name, err)
}
}
}