Files
client-web/src/api/merchantIam.test.mjs
T

41 lines
2.1 KiB
JavaScript
Raw Normal View History

2026-07-30 17:59:42 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const source = readFileSync(new URL('./merchantIam.ts', import.meta.url), 'utf8')
const storeSource = readFileSync(new URL('../stores/tenantAdministration.ts', import.meta.url), 'utf8')
test('declares the documented merchant role and member endpoints', () => {
assert.match(source, /url: '\/merchant\/v1\/iam\/roles'/)
assert.match(source, /url: '\/merchant\/v1\/iam\/roles\/permissions'/)
assert.match(source, /url: '\/merchant\/v1\/iam\/members'/)
assert.match(source, /url: '\/merchant\/v1\/iam\/members\/roles'/)
assert.match(source, /url: `\/merchant\/v1\/iam\/members\/\$\{membershipId\}`/)
assert.match(source, /url: `\/merchant\/v1\/iam\/members\/\$\{membershipId\}\/status`/)
assert.match(source, /url: `\/merchant\/v1\/iam\/members\/\$\{membershipId\}\/password`/)
assert.match(source, /url: '\/merchant\/v1\/iam\/profile'/)
})
test('supports tenant profile updates and authenticated qualification downloads', () => {
assert.match(source, /method: 'PUT', url: '\/merchant\/v1\/iam\/tenant\/profile'/)
assert.match(source, /apiBlobRequest\(\{ method: 'GET', url \}\)/)
assert.match(source, /url\.startsWith\('\/merchant\/v1\/files\/qualifications\/'\)/)
assert.match(storeSource, /await updateTenantProfile/)
})
test('uses membershipId and full replacement arrays in authorization writes', () => {
assert.match(source, /data: \{ roleId, permissionIds \}/)
assert.match(source, /data: \{ membershipId, roleIds \}/)
assert.doesNotMatch(source, /data: \{ userId, roleIds \}/)
})
test('clears mock records before loading server role and member lists', () => {
assert.match(storeSource, /rolesLoadedFromApi\.value = true\s+roles\.value = \[\]/)
assert.match(storeSource, /membersLoadedFromApi\.value = true\s+members\.value = \[\]/)
assert.match(storeSource, /await createMerchantRole/)
assert.match(storeSource, /await createMerchantMember/)
assert.match(storeSource, /await updateMerchantMember/)
assert.match(storeSource, /await changeMerchantMemberStatus/)
assert.match(storeSource, /await resetMerchantMemberPassword/)
})