Files
client-web/src/modules/notifications/notifications.test.mjs
T
2026-08-12 19:30:17 +08:00

39 lines
1.9 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
const moduleRoot = new URL('./', import.meta.url)
test('activates message-center routes with the frozen merchant permission', async () => {
const source = await readFile(new URL('routes.ts', moduleRoot), 'utf8')
assert.match(source, /name: 'notifications-list'[\s\S]*release: 'active'/)
assert.match(source, /name: 'notification-detail'[\s\S]*release: 'active'/)
assert.match(source, /merchant:notification:view/)
})
test('does not accept browser-selected customer or user scope in the API boundary', async () => {
const source = await readFile(new URL('api/notifications.ts', moduleRoot), 'utf8')
assert.doesNotMatch(source, /tenantId|customerId|merchantId|userId/)
assert.match(source, /merchant\/v1\/notifications/)
assert.match(source, /unread-count/)
assert.match(source, /notifications\/\$\{encodeURIComponent\(id\)\}/)
assert.match(source, /notifications\/\$\{encodeURIComponent\(id\)\}\/read/)
assert.match(source, /read-all/)
assert.match(source, /category: query\.type/)
assert.match(source, /method: 'PUT'/)
assert.doesNotMatch(source, /method: 'POST'/)
})
test('keeps customer message actions first and covers the requested local states', async () => {
const source = await readFile(new URL('views/NotificationsView.vue', moduleRoot), 'utf8')
const operationColumn = source.indexOf('label="操作"')
const titleColumn = source.indexOf('label="消息标题"')
assert.ok(operationColumn >= 0 && operationColumn < titleColumn)
assert.match(source, /全部标为已读/)
assert.match(source, /标为已读/)
assert.match(source, /state-panel--error/)
assert.match(source, /暂无消息/)
assert.doesNotMatch(source, /清空已读|删除消息/)
assert.match(source, /Promise\.all\(\[load\(\), notifications\.refreshUnreadCount\(\)\]\)/)
})