CaiWuXiTong/tests/Feature/Console/PushSupplierZeroDifferenceConfirmationsTest.php
苏木 d7b664ad53 fix(供应商对账): 批量推送命令切换到指定公司上下文 (#1710)
批量推送命令先激活指定公司上下文,确保读取网页中已配置的钉钉机器人和对账设置。
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
2026-12-03 18:20:14 +08:00

85 lines
3.4 KiB
PHP

<?php
namespace Tests\Feature\Console;
use Mockery;
use Modules\EcommerceFinance\Services\SupplierStatementStore;
use Modules\EcommerceFinance\Services\SupplierZeroDifferenceConfirmation;
use Tests\Feature\FeatureTestCase;
class PushSupplierZeroDifferenceConfirmationsTest extends FeatureTestCase
{
public function test_dry_run_reports_eligible_suppliers_without_pushing(): void
{
$companyId = (int) $this->company->id;
$statements = Mockery::mock(SupplierStatementStore::class);
$statements->shouldReceive('uploadedSuppliers')->once()->with($companyId)->andReturn(['零差异厂家', '有差异厂家']);
$this->app->instance(SupplierStatementStore::class, $statements);
$confirmation = Mockery::mock(SupplierZeroDifferenceConfirmation::class);
$confirmation->shouldReceive('assess')
->once()
->with('零差异厂家', $companyId, '2026-11')
->andReturn($this->assessment(true, '零差异厂家', 12, 1200));
$confirmation->shouldReceive('assess')
->once()
->with('有差异厂家', $companyId, '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' => $companyId,
'--dry-run' => true,
])->expectsOutputToContain('未发送任何消息')
->assertSuccessful();
}
public function test_real_run_pushes_eligible_suppliers_and_skips_existing_confirmations(): void
{
$companyId = (int) $this->company->id;
$statements = Mockery::mock(SupplierStatementStore::class);
$statements->shouldReceive('uploadedSuppliers')->once()->with($companyId)->andReturn(['零差异厂家']);
$this->app->instance(SupplierStatementStore::class, $statements);
$confirmation = Mockery::mock(SupplierZeroDifferenceConfirmation::class);
$confirmation->shouldReceive('pushMonth')
->once()
->with('零差异厂家', $companyId, '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' => $companyId,
])->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,
];
}
}