CaiWuXiTong/tests/Feature/Console/SyncDingProcessDetailMirrorTest.php

142 lines
5.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Console;
use Mockery;
use Modules\EcommerceFinance\Services\DingInvoiceSyncService;
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorSynchronizer;
use Tests\Feature\FeatureTestCase;
class SyncDingProcessDetailMirrorTest extends FeatureTestCase
{
public function test_business_id_option_runs_targeted_dry_run(): void
{
$synchronizer = Mockery::mock(DingProcessDetailMirrorSynchronizer::class);
$synchronizer->shouldReceive('syncBusinessIds')
->once()
->with(
['202610151743000310225', '202610151743000310226'],
true,
true,
)
->andReturn([
'status' => 'validated',
'run_mode' => 'business_ids',
'workflows' => 1,
'details' => 2,
'payments' => 1,
'amount_total' => 15535.37,
'bank_amount_total' => 15535.37,
]);
$this->app->instance(DingProcessDetailMirrorSynchronizer::class, $synchronizer);
$this->artisan('business-mirror:sync-ding-process-details', [
'--business-id' => '202610151743000310225,202610151743000310226',
'--dry-run' => true,
])
->expectsOutputToContain('校验通过:1 个审批,2 条明细,1 笔付款')
->assertSuccessful();
}
public function test_business_id_option_can_skip_approval_api(): void
{
$synchronizer = Mockery::mock(DingProcessDetailMirrorSynchronizer::class);
$synchronizer->shouldReceive('syncBusinessIds')
->once()
->with(['202610151743000310225'], false, false)
->andReturn([
'status' => 'succeeded',
'run_mode' => 'business_ids',
'workflows' => 1,
'details' => 1,
'payments' => 1,
'amount_total' => 100.0,
'bank_amount_total' => 100.0,
]);
$this->app->instance(DingProcessDetailMirrorSynchronizer::class, $synchronizer);
$this->artisan('business-mirror:sync-ding-process-details', [
'--business-id' => '202610151743000310225',
'--skip-approval-api' => true,
])->assertSuccessful();
}
public function test_full_and_business_id_cannot_be_combined(): void
{
$synchronizer = Mockery::mock(DingProcessDetailMirrorSynchronizer::class);
$synchronizer->shouldNotReceive('sync');
$synchronizer->shouldNotReceive('syncBusinessIds');
$this->app->instance(DingProcessDetailMirrorSynchronizer::class, $synchronizer);
$this->artisan('business-mirror:sync-ding-process-details', [
'--full' => true,
'--business-id' => '202610151743000310225',
])->assertFailed();
}
public function test_incremental_oa_sync_runs_bounded_invoice_scan(): void
{
config([
'ding_invoice_data.sync_with_oa_process' => true,
'ding_invoice_data.auto_scan_limit' => 5,
]);
$synchronizer = Mockery::mock(DingProcessDetailMirrorSynchronizer::class);
$synchronizer->shouldReceive('sync')
->once()
->with(false, false)
->andReturn([
'status' => 'succeeded',
'run_mode' => 'incremental',
'workflows' => 2,
'details' => 3,
'payments' => 2,
'amount_total' => 100.0,
'bank_amount_total' => 100.0,
]);
$this->app->instance(DingProcessDetailMirrorSynchronizer::class, $synchronizer);
$invoices = Mockery::mock(DingInvoiceSyncService::class);
$invoices->shouldReceive('latestPendingMonth')->once()->andReturn('2026-10');
$invoices->shouldReceive('syncMonth')
->once()
->with('2026-10', 5)
->andReturn([
'processed_flows' => 5,
'recognized_invoices' => 2,
'preserved_invoices' => 3,
'remaining_flows' => 9,
]);
$this->app->instance(DingInvoiceSyncService::class, $invoices);
$this->artisan('business-mirror:sync-ding-process-details')
->expectsOutputToContain('发票增量识别完成')
->assertSuccessful();
}
public function test_oa_sync_skips_invoices_when_no_workflow_changed(): void
{
$synchronizer = Mockery::mock(DingProcessDetailMirrorSynchronizer::class);
$synchronizer->shouldReceive('sync')
->once()
->with(false, false)
->andReturn([
'status' => 'succeeded',
'run_mode' => 'incremental',
'workflows' => 0,
'details' => 0,
'payments' => 0,
'amount_total' => 0.0,
'bank_amount_total' => 0.0,
]);
$this->app->instance(DingProcessDetailMirrorSynchronizer::class, $synchronizer);
$invoices = Mockery::mock(DingInvoiceSyncService::class);
$invoices->shouldNotReceive('latestPendingMonth');
$invoices->shouldNotReceive('syncMonth');
$this->app->instance(DingInvoiceSyncService::class, $invoices);
$this->artisan('business-mirror:sync-ding-process-details')->assertSuccessful();
}
}