import assert from 'node:assert/strict' import test from 'node:test' import * as loading from './phase3-loading.mjs' test('cached loading module resolves each fresh customer independently', () => { const context={context:{merchantQualificationFixture:{username:'customer-a',password:'test-a'}},options:{merchantUsername:'configured',merchantPassword:'configured-test'}} assert.deepEqual(loading.loadingMerchantCredentials(context),{username:'customer-a',password:'test-a'}) context.context.merchantQualificationFixture={username:'customer-b',password:'test-b'} assert.deepEqual(loading.loadingMerchantCredentials(context),{username:'customer-b',password:'test-b'}) }) test('explicit credentials take precedence; environment is read at invocation', () => { const env={MERCHANT_TEST_USERNAME:'env-a',MERCHANT_TEST_PASSWORD:'test-env-a'} assert.deepEqual(loading.loadingMerchantCredentials({options:{merchantUsername:'configured',merchantPassword:'test-configured'}},env),{username:'configured',password:'test-configured'}) assert.deepEqual(loading.loadingMerchantCredentials({},env),{username:'env-a',password:'test-env-a'}) env.MERCHANT_TEST_USERNAME='env-b';env.MERCHANT_TEST_PASSWORD='test-env-b' assert.deepEqual(loading.loadingMerchantCredentials({},env),{username:'env-b',password:'test-env-b'}) }) test('incomplete selected identity cannot fall back to another customer', () => { const env={MERCHANT_TEST_USERNAME:'unrelated',MERCHANT_TEST_PASSWORD:'unrelated-test'} for(const context of [{context:{merchantQualificationFixture:{username:'current'}}},{options:{merchantPassword:'orphan-test'}}]) { assert.throws(()=>loading.loadingMerchantCredentials(context,env),/完整客户登录凭据/) } }) test('loading stops before business requests when its current customer lacks credentials', async () => { let requests=0 await assert.rejects(loading.run({context:{merchantQualificationFixture:{username:'missing-password'}},options:{},createdResources:{},addStep(){},request:async()=>{requests++;throw Error('business request must not run')}}),/完整客户登录凭据/) assert.equal(requests,0) })