feat: 支持管理员消息推送
This commit is contained in:
@@ -22,6 +22,7 @@ const makeUser = (overrides: Record<string, unknown> = {}) => ({
|
||||
nickname: 'Alice',
|
||||
avatarUrl: 'https://example.com/avatar.png',
|
||||
role: UserRole.MEMBER,
|
||||
adminBookingSubscriptionCount: 0,
|
||||
createdAt: new Date('2024-01-01T00:00:00Z'),
|
||||
updatedAt: new Date('2024-01-01T00:00:00Z'),
|
||||
_count: { memberships: 2 },
|
||||
@@ -119,12 +120,20 @@ describe('UserService', () => {
|
||||
avatarUrl: 'https://example.com/avatar.png',
|
||||
role: UserRole.MEMBER,
|
||||
activeMembershipCount: 3,
|
||||
adminBookingSubscriptionCount: 0,
|
||||
subscriptionMessageTemplates: {
|
||||
templates: [
|
||||
{
|
||||
templateId: 'tmpl-booking-confirmed',
|
||||
scene: SubscriptionMessageScene.BOOKING_CREATED,
|
||||
description: '购卡或预约时请求一次订阅,用于后续预约确认通知推送',
|
||||
usageTarget: 'consent',
|
||||
},
|
||||
{
|
||||
templateId: 'tmpl-booking-confirmed',
|
||||
scene: SubscriptionMessageScene.ADMIN_BOOKING_CREATED,
|
||||
description: '管理员主动增加预约提醒次数,用于接收学员新预约通知',
|
||||
usageTarget: 'counter',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -255,7 +264,38 @@ describe('UserService', () => {
|
||||
expect(result.nickname).toBe('Bob')
|
||||
expect(result.avatarUrl).toBe('https://example.com/new.png')
|
||||
expect(result.activeMembershipCount).toBe(1)
|
||||
expect(result.subscriptionMessageTemplates.templates).toHaveLength(1)
|
||||
expect(result.adminBookingSubscriptionCount).toBe(0)
|
||||
expect(result.subscriptionMessageTemplates.templates).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('increments admin booking subscription count for admin users', async () => {
|
||||
mockPrisma.user.findUnique.mockResolvedValue(makeUser({
|
||||
role: UserRole.ADMIN,
|
||||
adminBookingSubscriptionCount: 2,
|
||||
}))
|
||||
mockPrisma.user.update.mockResolvedValue(makeUser({
|
||||
role: UserRole.ADMIN,
|
||||
adminBookingSubscriptionCount: 3,
|
||||
}))
|
||||
|
||||
const result = await service.grantAdminBookingSubscriptionCount('user-1')
|
||||
|
||||
expect(mockPrisma.user.update).toHaveBeenCalledWith({
|
||||
where: { id: 'user-1' },
|
||||
data: {
|
||||
adminBookingSubscriptionCount: {
|
||||
increment: 1,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
memberships: { where: { status: MembershipStatus.ACTIVE } },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(result.adminBookingSubscriptionCount).toBe(3)
|
||||
})
|
||||
|
||||
it('only includes provided fields in the update payload', async () => {
|
||||
|
||||
Reference in New Issue
Block a user