CaiWuXiTong/tests/Feature/Business/ProcessDetailsPageTest.php
yueyang 2cf75ac10b feat: 按出纳节点重做流程付款状态 (#685)
付款状态改由出纳任务节点判断,金额差额独立展示。
2026-10-27 14:01:23 +08:00

167 lines
7.0 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Mockery;
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
use RuntimeException;
use Tests\Feature\FeatureTestCase;
class ProcessDetailsPageTest extends FeatureTestCase
{
public function test_page_renders_process_detail_rows_and_filters(): void
{
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
$repository->shouldReceive('paginate')->once()->andReturn([
'data' => [
(object) [
'business_id' => '202601011200000000001',
'line_no' => 1,
'originator_name' => '张三',
'status' => '已完成',
'payment_state' => '出纳已打款',
'payment_fact_amount' => 0,
'payment_difference' => 0.20,
'document_type' => '公摊日常报销',
'purpose' => '办公用品采购',
'account_code' => '5602.04',
'account_name' => '管理费用_办公费',
'amount' => 100.00,
'bank_account_code' => '1002.01.001',
'bank_account_name' => '华夏银行-测试',
'bank_amount' => 100.00,
'payment_method' => '银行卡',
'paid_at' => '2026-01-02 00:00',
],
],
'total' => 1,
'summary' => [
'rows' => 1,
'approvals' => 1,
'amount_total' => 100.0,
'bank_amount_total' => 100.0,
],
'status' => 'succeeded',
'last_synced_at' => '2026-10-26 15:00:00',
'sync_stale' => true,
'sync_stale_after_minutes' => 15,
'scope' => 'personal_permission',
]);
$repository->shouldReceive('filterOptions')->once()->andReturn([
'document_types' => ['公摊日常报销'],
'statuses' => ['已完成'],
'payment_states' => [
'出纳状态待同步',
'出纳未开始',
'出纳待打款',
'出纳退回',
'出纳已打款',
'流程终止',
'不涉及付款',
],
]);
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
$financeSection = collect(\App\Utilities\BusinessNavigation::all())
->firstWhere('slug', 'financial-operations');
$this->assertContains(
'process-details',
array_column($financeSection['pages'] ?? [], 'slug'),
);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'process-details',
]))->assertOk()
->assertSee('流程明细')
->assertSee('审批编号')
->assertSee('发起人')
->assertSee('单据类型')
->assertSee('打款日期')
->assertSee('name="paid_date"', false)
->assertSee('name="payment_state"', false)
->assertSee('审批状态')
->assertSee('付款状态')
->assertSee('出纳已打款')
->assertSee('出纳状态待同步')
->assertSee('付款金额')
->assertSee('付款差额')
->assertSee('0.20')
->assertSee('付款合计')
->assertDontSee('银行付款合计')
->assertSee('流程数据已超过 15 分钟未成功同步')
->assertSee('202601011200000000001')
->assertSee('张三')
->assertSee('管理费用_办公费')
->assertSee('100.00')
->assertSee('当前账号权限范围')
->assertSee('同一笔付款不会因关联多条费用而重复计算')
->assertSee('导出');
}
public function test_page_stays_readable_when_mirror_is_not_ready(): void
{
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
$repository->shouldReceive('paginate')->once()->andThrow(new RuntimeException('not ready'));
$repository->shouldReceive('scope')->once()->andReturn('personal_permission');
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'process-details',
]))->assertOk()
->assertSee('流程明细镜像尚未完成导入')
->assertSee('当前账号权限范围');
}
public function test_export_streams_filtered_csv(): void
{
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
$repository->shouldReceive('ready')->once()->andReturn(true);
$repository->shouldReceive('exportRows')->once()->andReturnUsing(function (): \Generator {
yield [
'business_id' => '202601011200000000001',
'originator_name' => '张三',
'status' => '已完成',
'payment_state' => '出纳已打款',
'payment_difference' => 0.20,
'document_type' => '公摊日常报销',
'purpose' => '办公用品采购',
'line_no' => 1,
'account_code' => '5602.04',
'account_name' => '管理费用_办公费',
'amount' => '100.00',
'bank_account_code' => '1002.01.001',
'bank_account_name' => '华夏银行-测试',
'bank_amount' => '100.00',
'payment_method' => '银行卡',
'paid_at' => '2026-01-02 00:00',
];
});
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
$response = $this->loginAs()->get(route('business.process-details.export', [
'status' => '已完成',
'payment_state' => '出纳已打款',
]));
$response->assertOk();
$content = $response->streamedContent();
$this->assertStringContainsString('审批编号', $content);
$this->assertStringContainsString('202601011200000000001', $content);
$this->assertStringContainsString('张三', $content);
$this->assertStringContainsString('管理费用_办公费', $content);
$this->assertStringContainsString('付款状态', $content);
$this->assertStringContainsString('出纳已打款', $content);
$this->assertStringContainsString('付款差额', $content);
$this->assertStringContainsString('0.20', $content);
}
}