This commit is contained in:
2026-10-22 11:56:47 +08:00
parent 5d71af1ac9
commit de96e47d74
71 changed files with 1296 additions and 332 deletions
@@ -3,10 +3,40 @@ import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { run } from './phase4-overseas-business.mjs'
import { run, createPartnerWarehouse, retirePartnerWarehouse } from './phase4-overseas-business.mjs'
test('fixed partner warehouse is reused and never retired', async () => {
const calls = []
const context = { options: { fixedCustomerId: '123' }, marker: 'RUN', createdResources: {},
async request(method, path) { calls.push({ method, path }); return { body: { data: [{ warehouseId: '456' }] } } },
apiSuccess(_module, _name, response) { return response.body.data },
}
const warehouse = await createPartnerWarehouse(context)
assert.equal(warehouse.id, '456')
await retirePartnerWarehouse(context, warehouse)
assert.equal(calls.length, 1)
assert.equal(calls[0].method, 'GET')
})
const here = path.dirname(fileURLToPath(import.meta.url))
const source = fs.readFileSync(path.join(here, 'phase4-overseas-business.mjs'), 'utf8')
test('fixed customer beyond first page is found without creating or retiring a partner warehouse', async () => {
const context = fixture(), request = context.request.bind(context), pages = []
context.options = { fixedCustomerId: '10001' }
context.request = async (method, path, ...args) => {
if (path.startsWith('/api/platform/v1/iam/tenants?')) {
pages.push(path)
if (path.includes('page=1&')) return response({ ...page([{ id: '9999', status: 'ACTIVE' }]), size: 200, total: 201, pages: 2 })
return response(page([{ id: '10001', tenantName: '客户甲', status: 'ACTIVE' }]))
}
return request(method, path, ...args)
}
await run(context)
assert.equal(pages.length, 2)
assert.ok(context.createdResources.phase4OverseasBusiness.purchase)
assert.ok(context.calls.filter(call => call.path.includes('/warehouse-admin')).every(call => call.method === 'GET'))
})
function response(data, code = '200') {
return { http: 200, body: { code, message: code === '200' ? 'success' : 'conflict', data },
requestId: `request-${code}`, traceId: `trace-${code}` }