88 lines
3.5 KiB
PHP
88 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class FinanceLedgerPayableMappingBulkTest 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' => '甲工行', 'account_type' => '公户'],
|
|
['company_name' => '唯一公户测试公司乙', 'account_short' => '乙中行', 'account_type' => '公户'],
|
|
['company_name' => '唯一公户测试公司乙', 'account_short' => '乙支付宝', 'account_type' => '支付宝'],
|
|
['company_name' => '多公户测试公司丙', 'account_short' => '丙中行', 'account_type' => '公户'],
|
|
['company_name' => '多公户测试公司丙', 'account_short' => '丙华夏', 'account_type' => '公户'],
|
|
]);
|
|
$connection->table('fin_account_map')->insert([
|
|
['source' => 'payable', 'source_value' => '唯一账户测试公司甲', 'account_short' => null],
|
|
['source' => 'payable', 'source_value' => '唯一公户测试公司乙', 'account_short' => null],
|
|
['source' => 'payable', 'source_value' => '多公户测试公司丙', 'account_short' => null],
|
|
['source' => 'payable', 'source_value' => '无账户测试公司丁', 'account_short' => null],
|
|
]);
|
|
}
|
|
|
|
private function previewUrl(): string
|
|
{
|
|
return route('business.financial-ledger.mapping.payable.preview', [
|
|
'company_id' => $this->company->id,
|
|
]);
|
|
}
|
|
|
|
private function applyUrl(): string
|
|
{
|
|
return route('business.financial-ledger.mapping.payable.apply', [
|
|
'company_id' => $this->company->id,
|
|
]);
|
|
}
|
|
|
|
public function test_preview_and_apply_single_account_or_single_public_account(): void
|
|
{
|
|
$this->loginAs()->postJson($this->previewUrl())
|
|
->assertOk()
|
|
->assertJsonPath('total', 4)
|
|
->assertJsonPath('eligible', 2)
|
|
->assertJsonPath('ambiguous', 1)
|
|
->assertJsonPath('missing', 1);
|
|
|
|
$this->loginAs()->postJson($this->applyUrl())
|
|
->assertOk()
|
|
->assertJsonPath('mapped', 2)
|
|
->assertJsonPath('ambiguous', 1)
|
|
->assertJsonPath('missing', 1);
|
|
|
|
$this->assertDatabaseHas('fin_account_map', [
|
|
'source' => 'payable',
|
|
'source_value' => '唯一账户测试公司甲',
|
|
'account_short' => '甲工行',
|
|
'updated_by' => 'Test User',
|
|
], 'business_mirror');
|
|
$this->assertDatabaseHas('fin_account_map', [
|
|
'source' => 'payable',
|
|
'source_value' => '唯一公户测试公司乙',
|
|
'account_short' => '乙中行',
|
|
], 'business_mirror');
|
|
$this->assertDatabaseHas('fin_account_map', [
|
|
'source' => 'payable',
|
|
'source_value' => '多公户测试公司丙',
|
|
'account_short' => null,
|
|
], 'business_mirror');
|
|
$this->assertDatabaseHas('fin_account_map', [
|
|
'source' => 'payable',
|
|
'source_value' => '无账户测试公司丁',
|
|
'account_short' => null,
|
|
], 'business_mirror');
|
|
$this->assertDatabaseCount('fin_account_map_events', 2, 'business_mirror');
|
|
}
|
|
}
|