fix: 修复月卡无法编辑次数的问题
This commit is contained in:
@@ -544,6 +544,123 @@ describe('UserService', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateUserMembership', () => {
|
||||
const startDate = '2026-09-01'
|
||||
const expireDate = '2099-10-01'
|
||||
|
||||
it('snapshots a submitted count when creating a DURATION membership', async () => {
|
||||
mockPrisma.membership.findFirst.mockResolvedValue(null)
|
||||
mockPrisma.membership.create.mockResolvedValue({ id: 'mem-duration-001' })
|
||||
|
||||
await service.updateUserMembership('user-1', {
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 10,
|
||||
startDate,
|
||||
expireDate,
|
||||
})
|
||||
|
||||
expect(mockPrisma.membership.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
userId: 'user-1',
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 10,
|
||||
totalTimes: 10,
|
||||
status: MembershipStatus.ACTIVE,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('preserves the existing count snapshot when the submitted remaining count does not exceed it', async () => {
|
||||
mockPrisma.membership.findFirst.mockResolvedValue({
|
||||
id: 'mem-duration-001',
|
||||
userId: 'user-1',
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 6,
|
||||
totalTimes: 10,
|
||||
})
|
||||
mockPrisma.membership.update.mockResolvedValue({ id: 'mem-duration-001' })
|
||||
|
||||
await service.updateUserMembership('user-1', {
|
||||
membershipId: 'mem-duration-001',
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 8,
|
||||
startDate,
|
||||
expireDate,
|
||||
})
|
||||
|
||||
expect(mockPrisma.membership.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
where: { id: 'mem-duration-001' },
|
||||
data: expect.objectContaining({
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 8,
|
||||
totalTimes: 10,
|
||||
status: MembershipStatus.ACTIVE,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('raises the count snapshot when the submitted remaining count exceeds it', async () => {
|
||||
mockPrisma.membership.findFirst.mockResolvedValue({
|
||||
id: 'mem-duration-001',
|
||||
userId: 'user-1',
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 6,
|
||||
totalTimes: 10,
|
||||
})
|
||||
mockPrisma.membership.update.mockResolvedValue({ id: 'mem-duration-001' })
|
||||
|
||||
await service.updateUserMembership('user-1', {
|
||||
membershipId: 'mem-duration-001',
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 12,
|
||||
startDate,
|
||||
expireDate,
|
||||
})
|
||||
|
||||
expect(mockPrisma.membership.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
remainingTimes: 12,
|
||||
totalTimes: 12,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('resets the count snapshot when changing to a different card type', async () => {
|
||||
mockPrisma.membership.findFirst.mockResolvedValue({
|
||||
id: 'mem-duration-001',
|
||||
userId: 'user-1',
|
||||
cardTypeId: 'card-duration-001',
|
||||
remainingTimes: 6,
|
||||
totalTimes: 10,
|
||||
})
|
||||
mockPrisma.membership.update.mockResolvedValue({ id: 'mem-duration-001' })
|
||||
|
||||
await service.updateUserMembership('user-1', {
|
||||
membershipId: 'mem-duration-001',
|
||||
cardTypeId: 'card-duration-002',
|
||||
remainingTimes: 8,
|
||||
startDate,
|
||||
expireDate,
|
||||
})
|
||||
|
||||
expect(mockPrisma.membership.update).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
data: expect.objectContaining({
|
||||
cardTypeId: 'card-duration-002',
|
||||
remainingTimes: 8,
|
||||
totalTimes: 8,
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteUserMembership', () => {
|
||||
it('expires only the selected membership', async () => {
|
||||
mockPrisma.membership.findFirst.mockResolvedValue({
|
||||
|
||||
Reference in New Issue
Block a user