45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { submitYouyidianNotification } from '@/lib/youyidian-notification-center'
|
|
|
|
describe('由壹点通知中心客户端', () => {
|
|
const originalFetch = global.fetch
|
|
|
|
beforeEach(() => {
|
|
process.env.YYD_NOTIFICATION_CENTER_URL = 'https://notify.example.com'
|
|
process.env.YYD_NOTIFICATION_CENTER_PROJECT_CODE = 'material_library'
|
|
process.env.YYD_NOTIFICATION_CENTER_PROJECT_SECRET = '123456789012345678901234'
|
|
})
|
|
|
|
afterEach(() => {
|
|
global.fetch = originalFetch
|
|
})
|
|
|
|
test('使用项目签名提交通知任务', async () => {
|
|
global.fetch = jest.fn(async (_url, init) => ({
|
|
ok: true,
|
|
status: 202,
|
|
json: async () => ({
|
|
id: 'notification-1',
|
|
projectCode: 'material_library',
|
|
status: 'pending',
|
|
recipientUserId: 'ding-user-1',
|
|
title: '【由壹点·素材库】待填写',
|
|
}),
|
|
})) as unknown as typeof fetch
|
|
|
|
const result = await submitYouyidianNotification({
|
|
idempotencyKey: 'survey.assignment.created:assignment-1',
|
|
recipientUserId: 'ding-user-1',
|
|
title: '待填写',
|
|
content: '请完成考核调研',
|
|
actionTitle: '立即填写',
|
|
actionUrl: 'https://sc.jiansun.vip/performance-survey/survey/1',
|
|
})
|
|
|
|
expect(result.id).toBe('notification-1')
|
|
const [, init] = (global.fetch as jest.Mock).mock.calls[0]
|
|
expect(init.headers['x-yyd-project-code']).toBe('material_library')
|
|
expect(init.headers['x-yyd-signature']).toMatch(/^[a-f0-9]{64}$/)
|
|
expect(init.headers['x-yyd-nonce']).toBeTruthy()
|
|
})
|
|
})
|