CaiWuXiTong/tests/Feature/Business/FinanceLedgerShopMappingBulkTest.php
shanshi 20dc695549 feat: 完善财务台账账户维护与分页体验 (#412)
合并账户维护、筛选、列设置、无刷新分页、录入模板及批量映射工具。
2026-10-21 11:00:56 +08:00

95 lines
3.6 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Illuminate\Support\Facades\DB;
use Tests\Feature\FeatureTestCase;
class FinanceLedgerShopMappingBulkTest extends FeatureTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
$connection = DB::connection('business_mirror');
$connection->table('fin_accounts')->insert([
['company_name' => '店铺映射测试公司', 'account_short' => '映射账户甲'],
['company_name' => '店铺映射测试公司', 'account_short' => '映射账户乙'],
]);
$connection->table('fin_shops')->insert([
['shop_name' => '天猫-映射店铺甲', 'account_short' => '映射账户甲'],
['shop_name' => '天猫-映射店铺乙', 'account_short' => '映射账户乙'],
['shop_name' => '天猫-映射店铺丙', 'account_short' => '/'],
]);
$connection->table('fin_account_map')->insert([
['source' => 'shop', 'source_value' => '天猫-映射店铺甲', 'account_short' => null],
['source' => 'shop', 'source_value' => '天猫-映射店铺乙', 'account_short' => null],
['source' => 'shop', 'source_value' => '天猫-映射店铺丙', 'account_short' => null],
['source' => 'shop', 'source_value' => '已经映射的店铺', 'account_short' => '映射账户甲'],
]);
}
private function previewUrl(): string
{
return route('business.financial-ledger.mapping.shop.preview', [
'company_id' => $this->company->id,
]);
}
private function applyUrl(): string
{
return route('business.financial-ledger.mapping.shop.apply', [
'company_id' => $this->company->id,
]);
}
public function test_preview_and_apply_only_exact_shop_name_matches(): void
{
$this->loginAs()->postJson($this->previewUrl())
->assertOk()
->assertJsonPath('total', 3)
->assertJsonPath('matched', 2)
->assertJsonPath('unmatched', 1)
->assertJsonCount(2, 'sample');
$this->assertDatabaseHas('fin_account_map', [
'source' => 'shop',
'source_value' => '天猫-映射店铺甲',
'account_short' => null,
], 'business_mirror');
$this->loginAs()->postJson($this->applyUrl())
->assertOk()
->assertJsonPath('mapped', 2)
->assertJsonPath('unmatched', 1);
$this->assertDatabaseHas('fin_account_map', [
'source' => 'shop',
'source_value' => '天猫-映射店铺甲',
'account_short' => '映射账户甲',
'updated_by' => 'Test User',
], 'business_mirror');
$this->assertDatabaseHas('fin_account_map', [
'source' => 'shop',
'source_value' => '天猫-映射店铺乙',
'account_short' => '映射账户乙',
], 'business_mirror');
$this->assertDatabaseHas('fin_account_map', [
'source' => 'shop',
'source_value' => '天猫-映射店铺丙',
'account_short' => null,
], 'business_mirror');
$this->assertDatabaseHas('fin_account_map', [
'source' => 'shop',
'source_value' => '已经映射的店铺',
'account_short' => '映射账户甲',
], 'business_mirror');
$this->assertDatabaseCount('fin_account_map_events', 2, 'business_mirror');
}
}