test(order): verify rejected XLSX imports preserve scoped database facts
This commit is contained in:
@@ -9,7 +9,7 @@ import { customerProfilePath } from './client-import-template-test-env.mjs'
|
||||
export async function execute(args = process.argv.slice(2), execArgs = process.execArgv, env = process.env) {
|
||||
if (!args.length || args.length === 1 && args[0] === '--plan') return { plan: true,
|
||||
writes: 'Two single-row XLSX PARTIAL imports must reject foreign customer addresses; source/error files may be retained; no retry or deletion' }
|
||||
if (args.length !== 5 || !args[4].startsWith('--python=')) throw Error('Explicit TEST, customer and bundled Python required')
|
||||
if (![5, 6].includes(args.length) || !args[4].startsWith('--python=')) throw Error('Explicit TEST, customer and bundled Python required')
|
||||
const options = executionOptions(args.slice(0, 3), execArgs, env)
|
||||
const credentials = parseEnv(await readFile(customerProfilePath(args[3], execArgs[0].slice(11)), 'utf8'))
|
||||
if (!credentials.MERCHANT_TEST_USERNAME || !credentials.MERCHANT_TEST_PASSWORD) throw Error('Missing control credentials')
|
||||
@@ -19,12 +19,26 @@ export async function execute(args = process.argv.slice(2), execArgs = process.e
|
||||
const config = { environment: 'TEST', base: options.base, runId: options.runId,
|
||||
source: { loginId: env.CHONGCHONG_MERCHANT_USERNAME, password: env.CHONGCHONG_MERCHANT_PASSWORD },
|
||||
control: { loginId: credentials.MERCHANT_TEST_USERNAME, password: credentials.MERCHANT_TEST_PASSWORD } }
|
||||
if (args[5]) {
|
||||
const profile = databaseProfilePath(args[5], execArgs[0].slice(11))
|
||||
const database = parseEnv(await readFile(profile, 'utf8'))
|
||||
if (database.CHONGCHONG_ENV?.toUpperCase() !== 'TEST') throw Error('TEST database required')
|
||||
for (const key of ['HOST', 'PORT', 'USERNAME', 'PASSWORD'])
|
||||
if (!database['CHONGCHONG_DB_' + key]) throw Error('Incomplete TEST database configuration')
|
||||
config.database = Object.fromEntries(['HOST', 'PORT', 'USERNAME', 'PASSWORD'].map(key => [key.toLowerCase(), database['CHONGCHONG_DB_' + key]]))
|
||||
}
|
||||
const child = spawn(python, ['-B', resolve(root, 'scripts/client-xlsx-address-probe.py')],
|
||||
{ cwd: root, windowsHide: true, stdio: ['pipe', 'inherit', 'inherit'] })
|
||||
child.stdin.end(JSON.stringify(config))
|
||||
const code = await new Promise((accept, reject) => { child.on('error', reject); child.on('close', accept) })
|
||||
return { success: code === 0, report: resolve(root, 'reports', `client-xlsx-address-${options.runId}`, 'report.json') }
|
||||
}
|
||||
export function databaseProfilePath(argument, environmentFile) {
|
||||
if (!argument.startsWith('--database-profile=')) throw Error('Unknown argument')
|
||||
const profile = resolve(argument.slice(19))
|
||||
if (profile !== resolve(dirname(environmentFile), 'test-database.env')) throw Error('Use explicit test-database.env beside TEST acceptance profile')
|
||||
return profile
|
||||
}
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href)
|
||||
execute().then(r => { console.log(JSON.stringify(r)); if (r.success === false) process.exitCode = 1 })
|
||||
.catch(() => { console.error('XLSX probe did not start; check explicit TEST inputs and unused run ID.'); process.exitCode = 1 })
|
||||
|
||||
Reference in New Issue
Block a user