test(fleet): isolate recovery actor phone generation
This commit is contained in:
@@ -448,7 +448,7 @@ export async function prepareFleetCostActors(context) {
|
||||
await request('PUT', `${base}/roles/permissions`, { roleId: actor.roleId, permissionIds: kind === 'reader' ? [id(list[0].id)] : [] })
|
||||
const password = `Fleet${randomUUID().replaceAll('-', '')}A9`
|
||||
const user = await request('POST', `${base}/users`, { username, displayName: `${context.marker}-${kind}`,
|
||||
phone: await context.findAvailablePhone(MODULE), email: `${username}@example.com`, tenantId: '0',
|
||||
phone: await findFleetActorPhone(context, suffix), email: `${username}@example.com`, tenantId: '0',
|
||||
roleIds: [actor.roleId], password, status: 'ACTIVE' })
|
||||
if (!id(user?.membershipId) || user.username !== username || id(user.tenantId) !== '0'
|
||||
|| user.roleIds?.length !== 1 || id(user.roleIds[0]) !== actor.roleId) throw Error('Fresh cost account ownership mismatch')
|
||||
@@ -469,6 +469,23 @@ export async function prepareFleetCostActors(context) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function findFleetActorPhone(context, actorSuffix) {
|
||||
if (!context.marker || !/^[a-f0-9]{16}$/.test(actorSuffix)) throw Error('Fresh actor phone scope required')
|
||||
for (let attempt = 0; attempt < 100; attempt++) {
|
||||
const number = createHash('sha256').update(`${context.marker}:${actorSuffix}:${attempt}`).digest().readUInt32BE(0)
|
||||
const phone = `18${String(number).padStart(9, '0').slice(-9)}`
|
||||
const users = await context.request('GET', `/api/platform/v1/iam/users?${new URLSearchParams({ page: '1', size: '20', keyword: phone })}`)
|
||||
if (!success(users) || !users.requestId || !users.traceId || !Array.isArray(users.body.data?.records)
|
||||
|| !Number.isSafeInteger(Number(users.body.data.total)) || Number(users.body.data.total) !== users.body.data.records.length)
|
||||
throw Error('Cannot verify platform actor phone availability')
|
||||
if (users.body.data.records.some(row => row.phone === phone)) continue
|
||||
const customer = await context.request('GET', `/api/platform/v1/iam/tenants/administrator-phone-availability?phone=${encodeURIComponent(phone)}`)
|
||||
if (!success(customer) || !customer.requestId || !customer.traceId) throw Error('Cannot verify customer administrator phone availability')
|
||||
if (customer.body.data === true) return phone
|
||||
}
|
||||
throw Error('No available phone in the fresh actor scope; do not replay user creation')
|
||||
}
|
||||
|
||||
export async function runFleetScenario(context, { wait = ms => new Promise(resolve => setTimeout(resolve, ms)), onHandoverReady,
|
||||
costActors, resumeFull = false, resumePersisted = false, resumeReceiptReady = false, resumePalletized = false, resumeReceiptConfirmed = false, terminalReadOnly = false } = {}) {
|
||||
if (terminalReadOnly) return verifyFleetTerminalState(context)
|
||||
|
||||
Reference in New Issue
Block a user