Files
baiyue-firstleg/scripts/client-notifications-contract.test.mjs
2026-10-22 11:56:47 +08:00

49 lines
2.2 KiB
JavaScript

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('fixed customer acceptance excludes notification writes and reports incomplete coverage', () => {
const orchestration = source.match(/try\s*\{\s*await reuseFixedClient\(\)[\s\S]*?\} catch \(error\)/)?.[0] || ''
assert.match(orchestration, /'notification-inbox'/)
assert.match(orchestration, /recordSkipped\(module,/)
assert.doesNotMatch(orchestration, /await (?:isolationModule|notificationInboxModule|accountSecurityModule)\(/)
assert.match(orchestration, /report\.fullCoverage = !report\.steps\.some\(\(step\) => step\.skipped\)/)
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('excluded notification lifecycle targets only its fixture 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)
})