优化多账号选择

This commit is contained in:
yml2213
2026-05-29 22:34:41 +08:00
parent e5ad6f4918
commit f408fe1804
6 changed files with 1006 additions and 517 deletions
@@ -0,0 +1,129 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { syncDeliveryTasksForOrderWithDeps } from './delivery-task-service.js'
test('syncDeliveryTasksForOrder 多账号候选时不提前固定 cloudtentacles 账号', async () => {
const createdInputs: any[] = []
await syncDeliveryTasksForOrderWithDeps(
{
id: 1,
pay_status: 'pending_payment',
provider: 'open_91',
platform: 'kuaishou',
shop_id: 'shop-1',
shop_name: '测试店铺',
platform_order_id: '2614900602069169',
} as any,
[
{
id: 10,
order_id: 1,
sku_code: 'SKU-1',
sku_name: '荣耀勋章礼包(30个)',
quantity: 1,
item_snapshot_json: {
cloudtentacles: {
cloudSourceKeys: ['account-a', 'account-b'],
resolvedSourceKey: 'account-a',
cloudSkuId: 74,
cloudSkuName: '荣耀勋章礼包(30个)',
deliveryItems: [
{
cloudSkuId: 74,
cloudSkuName: '荣耀勋章礼包(30个)',
quantity: 1,
},
],
},
},
},
] as any,
{
listTasksByOrderId: async () => [],
getFulfillmentProfileByKey: async () => ({
id: 9,
profile_key: 'kuaishou_ct_assisted',
profile_name: '快手 cloud 履约',
executor_key: 'kuaishou_ct_assisted',
}),
createTask: async (input: any) => {
createdInputs.push(input)
return {
id: 100,
order_item_id: input.orderItemId,
context_json: input.contextJson,
task_status: input.taskStatus,
executor_key: input.executorKey,
} as any
},
nowIso: () => '2026-05-29T09:05:46.658Z',
randomId: () => 'DT-test',
},
)
const context = JSON.parse(createdInputs[0].contextJson)
assert.deepEqual(context.kuaishouCloudFulfillment.binding.cloudSourceKeys, [
'account-a',
'account-b',
])
assert.equal(context.kuaishouCloudFulfillment.binding.resolvedSourceKey, '')
})
test('syncDeliveryTasksForOrder 单账号候选时保留固定 cloudtentacles 账号', async () => {
const createdInputs: any[] = []
await syncDeliveryTasksForOrderWithDeps(
{
id: 2,
pay_status: 'pending_payment',
provider: 'open_91',
platform: 'kuaishou',
shop_id: 'shop-1',
shop_name: '测试店铺',
platform_order_id: '2614900602069170',
} as any,
[
{
id: 11,
order_id: 2,
sku_code: 'SKU-1',
sku_name: '荣耀勋章礼包(30个)',
quantity: 1,
item_snapshot_json: {
cloudtentacles: {
cloudSourceKeys: ['account-a'],
cloudSkuId: 74,
cloudSkuName: '荣耀勋章礼包(30个)',
},
},
},
] as any,
{
listTasksByOrderId: async () => [],
getFulfillmentProfileByKey: async () => ({
id: 9,
profile_key: 'kuaishou_ct_assisted',
profile_name: '快手 cloud 履约',
executor_key: 'kuaishou_ct_assisted',
}),
createTask: async (input: any) => {
createdInputs.push(input)
return {
id: 101,
order_item_id: input.orderItemId,
context_json: input.contextJson,
task_status: input.taskStatus,
executor_key: input.executorKey,
} as any
},
nowIso: () => '2026-05-29T09:05:46.658Z',
randomId: () => 'DT-test',
},
)
const context = JSON.parse(createdInputs[0].contextJson)
assert.deepEqual(context.kuaishouCloudFulfillment.binding.cloudSourceKeys, ['account-a'])
assert.equal(context.kuaishouCloudFulfillment.binding.resolvedSourceKey, 'account-a')
})