更新
This commit is contained in:
@@ -16,15 +16,18 @@ final class PromotionDeleteApiFake extends QywxCustomerAcquisitionApiService
|
||||
/** @var list<string> */
|
||||
public array $deleted = [];
|
||||
|
||||
public function __construct(private string $failLinkId = '')
|
||||
{
|
||||
public function __construct(
|
||||
private string $failLinkId = '',
|
||||
private string $failMessage = 'mock remote deletion failed',
|
||||
private int $failCode = 0
|
||||
) {
|
||||
}
|
||||
|
||||
public function deleteLink(string $linkId): void
|
||||
{
|
||||
$this->deleted[] = $linkId;
|
||||
if ($linkId === $this->failLinkId) {
|
||||
throw new RuntimeException('mock remote deletion failed');
|
||||
throw new RuntimeException($this->failMessage, $this->failCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +97,11 @@ try {
|
||||
'update_time' => $now,
|
||||
]);
|
||||
|
||||
$firstAttempt = new PromotionDeleteApiFake($secondRemoteId);
|
||||
$firstAttempt = new PromotionDeleteApiFake(
|
||||
$secondRemoteId,
|
||||
'企业微信获客助手接口失败[40058]:invalid range',
|
||||
40058
|
||||
);
|
||||
$message = '';
|
||||
try {
|
||||
WecomPromotionLogic::deletePool($poolId, (int) $admin['id'], $admin, $firstAttempt);
|
||||
@@ -116,6 +123,44 @@ try {
|
||||
$assert((int) Db::name('qywx_promotion_pool_member')->where('id', $memberId)->value('enabled') === 0, '方案删除后成员仍处于启用状态');
|
||||
$sync = Db::name('qywx_promotion_range_sync')->where('pool_id', $poolId)->find();
|
||||
$assert((int) ($sync['status'] ?? 0) === 4 && (string) ($sync['lock_token'] ?? '') === '', '方案删除后同步租约没有终止');
|
||||
|
||||
// 企业微信明确返回 invalid link_id,说明远端目标已不存在或当前应用已无法操作;
|
||||
// 删除应保持幂等并继续清理本地方案,不能让陈旧 link_id 永久阻塞用户。
|
||||
$staleRemoteId = 'contract_stale_' . $suffix;
|
||||
$stalePoolId = (int) Db::name('qywx_promotion_pool')->insertGetId([
|
||||
'name' => '失效链接删除测试',
|
||||
'public_key' => bin2hex(random_bytes(16)),
|
||||
'status' => 1,
|
||||
'owner_admin_id' => (int) $admin['id'],
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
$staleLinkId = (int) Db::name('qywx_promotion_link')->insertGetId([
|
||||
'pool_id' => $stalePoolId,
|
||||
'name' => '远端已失效链接',
|
||||
'wecom_url' => 'https://work.weixin.qq.com/ca/' . $staleRemoteId,
|
||||
'remote_link_id' => $staleRemoteId,
|
||||
'remote_status' => 1,
|
||||
'status' => 1,
|
||||
'owner_admin_id' => (int) $admin['id'],
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
$staleApi = new PromotionDeleteApiFake(
|
||||
$staleRemoteId,
|
||||
'企业微信获客助手接口失败[40058]:invalid link_id',
|
||||
40058
|
||||
);
|
||||
WecomPromotionLogic::deletePool($stalePoolId, (int) $admin['id'], $admin, $staleApi);
|
||||
$assert($staleApi->deleted === [$staleRemoteId], '失效链接没有请求企业微信删除接口');
|
||||
$assert(
|
||||
Db::name('qywx_promotion_pool')->where('id', $stalePoolId)->whereNotNull('delete_time')->count() === 1,
|
||||
'invalid link_id 阻塞了本地方案删除'
|
||||
);
|
||||
$assert(
|
||||
(int) Db::name('qywx_promotion_link')->where('id', $staleLinkId)->value('remote_status') === 2,
|
||||
'invalid link_id 没有按远端已删除状态收敛'
|
||||
);
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user