CaiWuXiTong/tests/Feature/Console/PushSupplierZeroDifferenceConfirmationsTest.php
苏木 2a908b9292 feat(供应商对账): 零差异上传自动推送确认 (#1709)
厂家上传账单后,双方明细、件数和货款金额完全一致时自动发送货款确认;有差异时保持原回执流程。
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
2026-12-03 18:12:29 +08:00

83 lines
3.2 KiB
PHP

<?php
namespace Tests\Feature\Console;
use Mockery;
use Modules\EcommerceFinance\Services\SupplierStatementStore;
use Modules\EcommerceFinance\Services\SupplierZeroDifferenceConfirmation;
use Tests\TestCase;
class PushSupplierZeroDifferenceConfirmationsTest extends TestCase
{
public function test_dry_run_reports_eligible_suppliers_without_pushing(): void
{
$statements = Mockery::mock(SupplierStatementStore::class);
$statements->shouldReceive('uploadedSuppliers')->once()->with(1)->andReturn(['零差异厂家', '有差异厂家']);
$this->app->instance(SupplierStatementStore::class, $statements);
$confirmation = Mockery::mock(SupplierZeroDifferenceConfirmation::class);
$confirmation->shouldReceive('assess')
->once()
->with('零差异厂家', 1, '2026-11')
->andReturn($this->assessment(true, '零差异厂家', 12, 1200));
$confirmation->shouldReceive('assess')
->once()
->with('有差异厂家', 1, '2026-11')
->andReturn($this->assessment(false, '仍有 2 条差异', 10, 1000, 2));
$confirmation->shouldNotReceive('pushMonth');
$this->app->instance(SupplierZeroDifferenceConfirmation::class, $confirmation);
$this->artisan('supplier-reconciliation:push-zero-difference-confirmations', [
'--month' => '2026-11',
'--company' => 1,
'--dry-run' => true,
])->expectsOutputToContain('未发送任何消息')
->assertSuccessful();
}
public function test_real_run_pushes_eligible_suppliers_and_skips_existing_confirmations(): void
{
$statements = Mockery::mock(SupplierStatementStore::class);
$statements->shouldReceive('uploadedSuppliers')->once()->with(1)->andReturn(['零差异厂家']);
$this->app->instance(SupplierStatementStore::class, $statements);
$confirmation = Mockery::mock(SupplierZeroDifferenceConfirmation::class);
$confirmation->shouldReceive('pushMonth')
->once()
->with('零差异厂家', 1, '2026-11', null, true)
->andReturn([
'status' => 'skipped',
'month' => '2026-11',
'reason' => '该账期已有待确认推送,默认不重复推送',
'qty' => 12,
'amount' => 1200,
'difference_count' => 0,
]);
$this->app->instance(SupplierZeroDifferenceConfirmation::class, $confirmation);
$this->artisan('supplier-reconciliation:push-zero-difference-confirmations', [
'--month' => '2026-11',
'--company' => 1,
])->expectsOutputToContain('已推送 0 家,跳过 1 家,失败 0 家')
->assertSuccessful();
}
/** @return array<string,mixed> */
private function assessment(
bool $eligible,
string $reason,
float $qty,
float $amount,
int $differenceCount = 0,
): array {
return [
'eligible' => $eligible,
'month' => '2026-11',
'reason' => $reason,
'qty' => $qty,
'amount' => $amount,
'difference_count' => $differenceCount,
];
}
}