优化 affiliate-dash 成功后绑定快照
This commit is contained in:
@@ -4,6 +4,7 @@ import assert from 'node:assert/strict'
|
|||||||
import {
|
import {
|
||||||
canReuseAffiliateDashBindSnapshot,
|
canReuseAffiliateDashBindSnapshot,
|
||||||
isAffiliateDashBindSnapshotStale,
|
isAffiliateDashBindSnapshotStale,
|
||||||
|
shouldRefreshAffiliateDashBindStateForSnapshot,
|
||||||
} from './kuaishou-cloud-claim-service.js'
|
} from './kuaishou-cloud-claim-service.js'
|
||||||
|
|
||||||
test('isAffiliateDashBindSnapshotStale detects bind uuid that belongs to old uid', () => {
|
test('isAffiliateDashBindSnapshotStale detects bind uuid that belongs to old uid', () => {
|
||||||
@@ -136,3 +137,47 @@ test('canReuseAffiliateDashBindSnapshot refuses mismatched bound account', () =>
|
|||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('shouldRefreshAffiliateDashBindStateForSnapshot keeps polling before submit', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRefreshAffiliateDashBindStateForSnapshot({
|
||||||
|
taskStatus: 'waiting_binding',
|
||||||
|
orderStatus: 'paid',
|
||||||
|
submitStatus: '',
|
||||||
|
}),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('shouldRefreshAffiliateDashBindStateForSnapshot stops after submit starts', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRefreshAffiliateDashBindStateForSnapshot({
|
||||||
|
taskStatus: 'redeeming',
|
||||||
|
orderStatus: 'delivering',
|
||||||
|
submitStatus: 'delivering',
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('shouldRefreshAffiliateDashBindStateForSnapshot stops after delivered', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRefreshAffiliateDashBindStateForSnapshot({
|
||||||
|
taskStatus: 'redeemed',
|
||||||
|
orderStatus: 'delivered',
|
||||||
|
submitStatus: 'delivered',
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('shouldRefreshAffiliateDashBindStateForSnapshot stops for failed platform result', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRefreshAffiliateDashBindStateForSnapshot({
|
||||||
|
taskStatus: 'retry_pending',
|
||||||
|
orderStatus: 'ship_failed',
|
||||||
|
submitStatus: '',
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|||||||
@@ -232,7 +232,9 @@ export async function getKuaishouCloudClaimDetail(token: unknown): Promise<Claim
|
|||||||
|
|
||||||
if (executorKey === 'affiliate_dash') {
|
if (executorKey === 'affiliate_dash') {
|
||||||
task = (await syncAffiliateDashTaskStatus(task)) || task
|
task = (await syncAffiliateDashTaskStatus(task)) || task
|
||||||
task = (await refreshAffiliateDashBindState(task)) || task
|
if (shouldRefreshAffiliateDashBindState(task)) {
|
||||||
|
task = (await refreshAffiliateDashBindState(task)) || task
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (executorKey === 'kuaishou-industry') {
|
if (executorKey === 'kuaishou-industry') {
|
||||||
@@ -722,6 +724,39 @@ export function canReuseAffiliateDashBindSnapshot(
|
|||||||
return !flow.bound || Boolean(boundAccount)
|
return !flow.bound || Boolean(boundAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldRefreshAffiliateDashBindStateForSnapshot(input: {
|
||||||
|
taskStatus?: unknown
|
||||||
|
orderStatus?: unknown
|
||||||
|
submitStatus?: unknown
|
||||||
|
}): boolean {
|
||||||
|
const taskStatus = String(input.taskStatus || '').trim()
|
||||||
|
if (
|
||||||
|
taskStatus === TASK_STATUS.REDEEMING ||
|
||||||
|
taskStatus === TASK_STATUS.DISPATCHED_PENDING_RETURN ||
|
||||||
|
taskStatus === TASK_STATUS.REDEEMED ||
|
||||||
|
taskStatus === TASK_STATUS.COMPLETED
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitStatus = String(input.submitStatus || '').trim()
|
||||||
|
if (submitStatus) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderStatus = String(input.orderStatus || '').trim()
|
||||||
|
return !['delivering', 'delivered', 'ship_failed', 'cancelled'].includes(orderStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldRefreshAffiliateDashBindState(task: TaskRow): boolean {
|
||||||
|
const flow = normalizeAffiliateDashFlow(parseTaskContextValue(task).affiliateDash)
|
||||||
|
return shouldRefreshAffiliateDashBindStateForSnapshot({
|
||||||
|
taskStatus: task.task_status,
|
||||||
|
orderStatus: flow.orderStatus,
|
||||||
|
submitStatus: flow.submitStatus,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function clearAffiliateDashBindSnapshot(
|
function clearAffiliateDashBindSnapshot(
|
||||||
flow: AffiliateDashFlowSnapshot,
|
flow: AffiliateDashFlowSnapshot,
|
||||||
expectedUid: unknown,
|
expectedUid: unknown,
|
||||||
|
|||||||
Reference in New Issue
Block a user