67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Http\Client\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Modules\EcommerceFinance\Services\DingTalkProcessInstanceClient;
|
|
use Tests\TestCase;
|
|
|
|
class DingTalkProcessInstanceClientTest extends TestCase
|
|
{
|
|
public function test_process_snapshots_fetches_and_parses_a_batch(): void
|
|
{
|
|
config([
|
|
'dingtalk.client_id' => 'test-client',
|
|
'dingtalk.client_secret' => 'test-secret',
|
|
'dingtalk.app_token_url' => 'https://example.test/token',
|
|
'dingtalk.timeout' => 3,
|
|
'dingtalk.process_concurrency' => 2,
|
|
]);
|
|
|
|
Http::fake([
|
|
'https://example.test/token*' => Http::response([
|
|
'errcode' => 0,
|
|
'access_token' => 'test-token',
|
|
'expires_in' => 7200,
|
|
]),
|
|
'https://api.dingtalk.com/v1.0/workflow/processInstances*' => function (Request $request) {
|
|
$processInstanceId = (string) ($request->data()['processInstanceId'] ?? '');
|
|
|
|
return Http::response([
|
|
'result' => [
|
|
'status' => 'RUNNING',
|
|
'result' => 'NONE',
|
|
'formComponentValues' => [[
|
|
'name' => '用途',
|
|
'value' => '批量读取-' . $processInstanceId,
|
|
]],
|
|
'tasks' => [[
|
|
'taskGroupName' => '出纳打款',
|
|
'status' => 'RUNNING',
|
|
'result' => 'NONE',
|
|
]],
|
|
'operationRecords' => [],
|
|
],
|
|
]);
|
|
},
|
|
]);
|
|
|
|
$result = app(DingTalkProcessInstanceClient::class)
|
|
->processSnapshots(['process-a', 'process-b']);
|
|
|
|
$this->assertFalse($result['fatal']);
|
|
$this->assertSame(2, $result['attempted']);
|
|
$this->assertSame([], $result['errors']);
|
|
$this->assertSame(
|
|
'批量读取-process-a',
|
|
$result['snapshots']['process-a']['form_values']['用途'],
|
|
);
|
|
$this->assertSame(
|
|
'批量读取-process-b',
|
|
$result['snapshots']['process-b']['form_values']['用途'],
|
|
);
|
|
Http::assertSentCount(3);
|
|
}
|
|
}
|