fix: 修复月卡无法编辑次数的问题

This commit is contained in:
richarjiang
2026-09-07 18:10:39 +08:00
parent 86ad9ee64f
commit 87d946adb5
17 changed files with 564 additions and 91 deletions

View File

@@ -23,6 +23,12 @@ const durationCard = {
durationDays: 30,
}
const limitedDurationCard = {
type: CardTypeCategory.DURATION,
totalTimes: 10,
durationDays: 30,
}
const trialCard = {
type: CardTypeCategory.TRIAL,
totalTimes: 1,
@@ -136,6 +142,27 @@ describe('computeMembershipGrant', () => {
expect(result.isRenewal).toBe(true)
expect(result.expireDate.getTime()).toBe(now.getTime() + 30 * 86_400_000)
})
it('stacks sessions for an active count-limited DURATION card', () => {
const expireDate = new Date('2026-07-01T00:00:00Z')
const result = computeMembershipGrant({
existing: {
remainingTimes: 3,
totalTimes: 10,
expireDate,
status: MembershipStatus.ACTIVE,
},
cardType: limitedDurationCard,
now,
})
expect(result).toMatchObject({
isRenewal: true,
remainingTimes: 13,
totalTimes: 20,
})
expect(result.expireDate.getTime()).toBe(expireDate.getTime() + 30 * 86_400_000)
})
})
describe('getMembershipRenewalHint', () => {
@@ -185,6 +212,26 @@ describe('getMembershipRenewalHint', () => {
})
})
it('returns times_low for a count-limited DURATION card', () => {
const hint = getMembershipRenewalHint(
[
membership({
cardTypeId: 'limited-duration-1',
remainingTimes: RENEWAL_TIMES_THRESHOLD,
expireDate: new Date(now.getTime() + 20 * 86_400_000).toISOString(),
cardType: { type: CardTypeCategory.DURATION },
}),
],
now,
)
expect(hint).toMatchObject({
kind: 'times_low',
cardTypeId: 'limited-duration-1',
remainingTimes: RENEWAL_TIMES_THRESHOLD,
})
})
it('does not recommend renewing a TRIAL card when times run low', () => {
const hint = getMembershipRenewalHint(
[