Files
client-web/src/modules/notifications/notifications.test.mjs
T

35 lines
1.6 KiB
JavaScript
Raw Normal View History

2026-08-12 18:24:03 +08:00
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import test from 'node:test'
const moduleRoot = new URL('./', import.meta.url)
2026-08-12 18:49:54 +08:00
test('activates message-center routes with the frozen merchant permission', async () => {
2026-08-12 18:24:03 +08:00
const source = await readFile(new URL('routes.ts', moduleRoot), 'utf8')
2026-08-12 18:49:54 +08:00
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/)
2026-08-12 18:24:03 +08:00
})
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/)
2026-08-12 18:49:54 +08:00
assert.match(source, /unread-count/)
2026-08-12 18:24:03 +08:00
assert.match(source, /read-all/)
2026-08-12 18:49:54 +08:00
assert.match(source, /category: query\.type/)
assert.match(source, /method: 'PUT'/)
assert.doesNotMatch(source, /method: 'POST'/)
2026-08-12 18:24:03 +08:00
})
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, /暂无消息/)
})