feat: 支持管理员消息推送
This commit is contained in:
@@ -84,14 +84,26 @@ describe('TimeSlotService', () => {
|
||||
expect(result[0].myBookingId).toBeNull()
|
||||
})
|
||||
|
||||
it('marks isBookedByMe=true and sets myBookingId when user has a CONFIRMED booking', async () => {
|
||||
const slot = makeSlot({ bookings: [{ id: 'booking-42' }] })
|
||||
it('marks isBookedByMe=true and sets my booking info when user has a CONFIRMED booking', async () => {
|
||||
const slot = makeSlot({ bookings: [{ id: 'booking-42', status: BookingStatus.CONFIRMED }] })
|
||||
mockPrisma.timeSlot.findMany.mockResolvedValueOnce([slot])
|
||||
|
||||
const result = await service.getAvailableSlots('2026-04-07', 'user-1')
|
||||
|
||||
expect(result[0].isBookedByMe).toBe(true)
|
||||
expect(result[0].myBookingId).toBe('booking-42')
|
||||
expect(result[0].myBookingStatus).toBe(BookingStatus.CONFIRMED)
|
||||
})
|
||||
|
||||
it('marks pending confirmation booking as already booked by current user', async () => {
|
||||
const slot = makeSlot({ bookings: [{ id: 'booking-99', status: BookingStatus.PENDING_CONFIRMATION }] })
|
||||
mockPrisma.timeSlot.findMany.mockResolvedValueOnce([slot])
|
||||
|
||||
const result = await service.getAvailableSlots('2026-04-07', 'user-1')
|
||||
|
||||
expect(result[0].isBookedByMe).toBe(true)
|
||||
expect(result[0].myBookingId).toBe('booking-99')
|
||||
expect(result[0].myBookingStatus).toBe(BookingStatus.PENDING_CONFIRMATION)
|
||||
})
|
||||
|
||||
it('excludes CLOSED slots from query', async () => {
|
||||
@@ -134,11 +146,12 @@ describe('TimeSlotService', () => {
|
||||
|
||||
expect(result[0].isBookedByMe).toBe(false)
|
||||
expect(result[0].myBookingId).toBeNull()
|
||||
expect(result[0].myBookingStatus).toBeNull()
|
||||
})
|
||||
|
||||
it('maps multiple slots correctly', async () => {
|
||||
const slots = [
|
||||
makeSlot({ id: 'slot-1', startTime: '09:00', bookings: [{ id: 'bk-1' }] }),
|
||||
makeSlot({ id: 'slot-1', startTime: '09:00', bookings: [{ id: 'bk-1', status: BookingStatus.CONFIRMED }] }),
|
||||
makeSlot({ id: 'slot-2', startTime: '10:00', bookings: [] }),
|
||||
]
|
||||
mockPrisma.timeSlot.findMany.mockResolvedValueOnce(slots)
|
||||
@@ -148,8 +161,10 @@ describe('TimeSlotService', () => {
|
||||
expect(result).toHaveLength(2)
|
||||
expect(result[0].isBookedByMe).toBe(true)
|
||||
expect(result[0].myBookingId).toBe('bk-1')
|
||||
expect(result[0].myBookingStatus).toBe(BookingStatus.CONFIRMED)
|
||||
expect(result[1].isBookedByMe).toBe(false)
|
||||
expect(result[1].myBookingId).toBeNull()
|
||||
expect(result[1].myBookingStatus).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -164,7 +179,20 @@ describe('TimeSlotService', () => {
|
||||
|
||||
const result = await service.getSlotById('slot-1')
|
||||
|
||||
expect(result).toEqual(slot)
|
||||
expect(result).toMatchObject({
|
||||
id: slot.id,
|
||||
date: '2026-04-07',
|
||||
startTime: slot.startTime,
|
||||
endTime: slot.endTime,
|
||||
capacity: slot.capacity,
|
||||
bookedCount: slot.bookedCount,
|
||||
status: slot.status,
|
||||
source: slot.source,
|
||||
templateId: slot.templateId,
|
||||
isBookedByMe: false,
|
||||
myBookingId: null,
|
||||
myBookingStatus: null,
|
||||
})
|
||||
expect(mockPrisma.timeSlot.findUnique).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ where: { id: 'slot-1' } }),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user