This commit is contained in:
2026-08-13 19:19:34 +08:00
parent 0f0ae612ca
commit df1471dc30
15 changed files with 152 additions and 273 deletions
@@ -4,13 +4,8 @@ import {
cancelTask,
changeTemplateStatus,
createNotification,
getInboxDetail,
getUnreadCount,
listInbox,
listTasks,
listTemplates,
markAllInboxRead,
markInboxRead,
retryTask,
updateTemplate,
} from './notificationCenter'
@@ -21,38 +16,12 @@ vi.mock('@/shared/api/http', () => ({
}))
const envelope = <T>(data: T) => ({ code: '200', data })
const inbox = { id: '9007199254740993', category: 'ORDER', title: '已发货', status: 'UNREAD' as const, sentAt: '2026-08-12T10:00:00Z', readAt: null }
const template = { id: 12, templateCode: 'ORDER_SENT', templateName: '订单已发货', category: 'ORDER', channel: 'IN_APP' as const, titleTemplate: '已发货', bodyTemplate: '正文', variableWhitelist: [], status: 'DRAFT' as const, version: 1 }
const task = { id: 13, taskNo: 'NT-13', category: 'ORDER', title: '已发货', status: 'CREATED' as const, recipientCount: 2, scheduledAt: null, sentAt: null, duplicated: false }
describe('notificationCenter API', () => {
beforeEach(() => vi.clearAllMocks())
it('uses the platform inbox paths and normalizes envelope pagination and ids', async () => {
vi.mocked(http.get).mockResolvedValueOnce(envelope({ records: [inbox], page: '1', size: '20', total: '1', pages: '1' }))
const result = await listInbox({ page: 1, size: 20, status: 'UNREAD' })
expect(http.get).toHaveBeenCalledWith('/platform/v1/notifications', { params: { page: 1, size: 20, status: 'UNREAD' } })
expect(result).toMatchObject({ page: 1, size: 20, total: 1, pages: 1 })
expect(result.records[0]?.id).toBe(String(inbox.id))
vi.mocked(http.get).mockResolvedValueOnce(envelope({ unreadCount: '7' }))
expect(await getUnreadCount()).toBe(7)
expect(http.get).toHaveBeenLastCalledWith('/platform/v1/notifications/unread-count')
})
it('gets and marks inbox messages without a request body', async () => {
vi.mocked(http.get).mockResolvedValueOnce(envelope({ ...inbox, body: '正文', sourceType: null, sourceId: null }))
vi.mocked(http.put)
.mockResolvedValueOnce(envelope({ ...inbox, body: '正文', sourceType: null, sourceId: null }))
.mockResolvedValueOnce(envelope({ updatedCount: '3' }))
await getInboxDetail('10/20')
await markInboxRead('10/20')
expect(await markAllInboxRead()).toBe(3)
expect(http.get).toHaveBeenCalledWith('/platform/v1/notifications/10%2F20')
expect(http.put).toHaveBeenNthCalledWith(1, '/platform/v1/notifications/10%2F20/read')
expect(http.put).toHaveBeenNthCalledWith(2, '/platform/v1/notifications/read-all')
})
it('posts the frozen create-notification DTO unchanged', async () => {
vi.mocked(http.post).mockResolvedValueOnce(envelope(task))
const payload = { tenantId: '0', templateCode: 'ORDER_SENT', recipientType: 'PLATFORM_ROLE' as const, roleCode: 'PLATFORM_ADMIN', variables: {}, scheduledAt: null, idempotencyKey: 'notification-1' }