Files
baiyue-firstleg/scripts/client-notifications-contract.test.mjs
T

48 lines
2.1 KiB
JavaScript
Raw Normal View History

2026-08-14 10:09:46 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
const scriptsDir = dirname(fileURLToPath(import.meta.url))
const source = readFileSync(resolve(scriptsDir, 'client-test-env-acceptance.mjs'), 'utf8')
test('Client full acceptance executes the real notification inbox flow', () => {
2026-10-08 17:07:57 +08:00
const isolation = source.indexOf('await isolationModule()')
const notifications = source.indexOf('await notificationInboxModule()')
const security = source.indexOf('await accountSecurityModule()')
assert.ok(isolation >= 0 && notifications > isolation && security > notifications)
2026-08-14 10:09:46 +08:00
assert.match(source, /async function notificationInboxModule\(\)/)
for (const permission of [
'merchant:notification:view',
'merchant:notification:read',
'merchant:notification:read-all',
]) assert.match(source, new RegExp(`['"]${permission}['"]`))
})
test('notification delivery targets only the newly registered customer owner', () => {
assert.match(source, /tenantId:\s*String\(report\.resources\.tenantId\)/)
assert.match(source, /recipientType:\s*['"]MEMBERSHIP['"]/)
assert.match(source, /recipientIds:\s*\[String\(report\.resources\.membershipId\)\]/)
assert.match(source, /await sendMessage\(1\)/)
assert.match(source, /await sendMessage\(2\)/)
assert.match(source, /other client cannot read first message detail/)
assert.match(source, /other client cannot see acceptance messages in inbox/)
assert.match(source, /\['A0403', 'A0404'\]\.includes\(String\(json\?\.code\)\)/)
})
test('notification flow covers unread, single read, read-all, and cleanup', () => {
for (const contract of [
/status=UNREAD/,
/status=READ/,
/\/unread-count/,
/\$\{firstMessageId\}\/read/,
/\/read-all/,
/single-message read is idempotent/,
/cleanup keeps acceptance messages read/,
/cleanup leaves no unread acceptance messages/,
/targetStatus:\s*['"]DISABLED['"]/,
/retainedAsRead:\s*true/,
]) assert.match(source, contract)
})