188 lines
6.8 KiB
PHP
188 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class FinanceLedgerAccountStatusTest extends FeatureTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
DB::connection('business_mirror')->table('fin_accounts')->insert([
|
|
'company_name' => '测试财务公司',
|
|
'account_short' => '测试账户',
|
|
'account_no' => '6222000000000001',
|
|
'bank_name' => '测试银行',
|
|
]);
|
|
}
|
|
|
|
private function pageUrl(): string
|
|
{
|
|
return route('business.pages.show', [
|
|
'company_id' => $this->company->id,
|
|
'section' => 'financial-ledger',
|
|
'page' => 'ledger',
|
|
]);
|
|
}
|
|
|
|
private function statusUrl(): string
|
|
{
|
|
return route('business.financial-ledger.accounts.status', [
|
|
'company_id' => $this->company->id,
|
|
]);
|
|
}
|
|
|
|
public function test_account_table_renders_status_selector_with_four_options(): void
|
|
{
|
|
$this->loginAs()->get($this->pageUrl())
|
|
->assertOk()
|
|
->assertSee('账户状态')
|
|
->assertSee('data-account-status', false)
|
|
->assertSee('正常')
|
|
->assertSee('网银异常')
|
|
->assertSee('限额')
|
|
->assertSee('工商注销')
|
|
->assertSee('name="accounts_short"', false)
|
|
->assertSee('name="accounts_status"', false)
|
|
->assertSee('name="accounts_region"', false)
|
|
->assertSee('name="accounts_type"', false)
|
|
->assertSee('未填写')
|
|
->assertSee('value="normal" selected', false);
|
|
}
|
|
|
|
public function test_account_filters_narrow_by_short_status_region_and_type(): void
|
|
{
|
|
$connection = DB::connection('business_mirror');
|
|
$connection->table('fin_accounts')->insert([
|
|
[
|
|
'company_name' => '筛选测试公司甲',
|
|
'account_short' => '筛选账户甲',
|
|
'region' => '上海',
|
|
'account_type' => '公户',
|
|
],
|
|
[
|
|
'company_name' => '筛选测试公司乙',
|
|
'account_short' => '筛选账户乙',
|
|
'region' => '杭州',
|
|
'account_type' => '个人卡',
|
|
],
|
|
]);
|
|
$connection->table('fin_account_statuses')->insert([
|
|
'account_short' => '筛选账户乙',
|
|
'status' => 'limited',
|
|
'updated_by' => 'Test User',
|
|
]);
|
|
|
|
$this->loginAs()->get(route('business.pages.show', [
|
|
'company_id' => $this->company->id,
|
|
'section' => 'financial-ledger',
|
|
'page' => 'ledger',
|
|
'accounts_short' => '筛选账户',
|
|
'accounts_status' => 'limited',
|
|
'accounts_region' => '杭州',
|
|
'accounts_type' => '个人卡',
|
|
]))
|
|
->assertOk()
|
|
->assertSee('data-account-short="筛选账户乙"', false)
|
|
->assertDontSee('data-account-short="筛选账户甲"', false)
|
|
->assertSee('value="limited" selected', false);
|
|
|
|
$this->loginAs()->get(route('business.pages.show', [
|
|
'company_id' => $this->company->id,
|
|
'section' => 'financial-ledger',
|
|
'page' => 'ledger',
|
|
'accounts_short' => '筛选账户',
|
|
'accounts_status' => 'normal',
|
|
]))
|
|
->assertOk()
|
|
->assertSee('data-account-short="筛选账户甲"', false)
|
|
->assertDontSee('data-account-short="筛选账户乙"', false);
|
|
|
|
$this->loginAs()->get(route('business.pages.show', [
|
|
'company_id' => $this->company->id,
|
|
'section' => 'financial-ledger',
|
|
'page' => 'ledger',
|
|
'accounts_short' => '测试账户',
|
|
'accounts_status' => 'normal',
|
|
'accounts_region' => '__empty__',
|
|
'accounts_type' => '__empty__',
|
|
]))
|
|
->assertOk()
|
|
->assertSee('data-account-short="测试账户"', false);
|
|
}
|
|
|
|
public function test_account_status_can_be_saved_and_updated_without_duplicate_rows(): void
|
|
{
|
|
$payload = [
|
|
'account_short' => '测试账户',
|
|
'status' => 'limited',
|
|
];
|
|
|
|
$this->loginAs()->postJson($this->statusUrl(), $payload)
|
|
->assertOk()
|
|
->assertJsonPath('status', 'limited')
|
|
->assertJsonPath('label', '限额');
|
|
|
|
$this->loginAs()->postJson($this->statusUrl(), [
|
|
'account_short' => '测试账户',
|
|
'status' => 'normal',
|
|
])->assertOk()->assertJsonPath('label', '正常');
|
|
|
|
$this->assertDatabaseCount('fin_account_statuses', 1, 'business_mirror');
|
|
$this->assertDatabaseHas('fin_account_statuses', [
|
|
'account_short' => '测试账户',
|
|
'status' => 'normal',
|
|
'updated_by' => 'Test User',
|
|
], 'business_mirror');
|
|
|
|
$this->loginAs()->get($this->pageUrl())
|
|
->assertOk()
|
|
->assertSee('value="normal" selected', false);
|
|
}
|
|
|
|
public function test_invalid_status_or_account_is_rejected(): void
|
|
{
|
|
$this->withExceptionHandling()->loginAs()->postJson($this->statusUrl(), [
|
|
'account_short' => '测试账户',
|
|
'status' => 'unknown',
|
|
])->assertUnprocessable()->assertJsonValidationErrors('status');
|
|
|
|
$this->withExceptionHandling()->loginAs()->postJson($this->statusUrl(), [
|
|
'account_short' => '不存在的账户',
|
|
'status' => 'limited',
|
|
])->assertUnprocessable()->assertJsonPath('message', '账户简称不存在,请刷新账户总表后重试。');
|
|
|
|
$this->assertDatabaseCount('fin_account_statuses', 0, 'business_mirror');
|
|
}
|
|
|
|
public function test_user_without_finance_editor_role_cannot_change_account_status(): void
|
|
{
|
|
$viewer = user_model_class()::create([
|
|
'name' => '只读测试用户',
|
|
'email' => 'ledger-viewer-' . uniqid() . '@example.com',
|
|
'password' => 'local-test-password',
|
|
'locale' => 'zh-CN',
|
|
'enabled' => 1,
|
|
'landing_page' => 'dashboard',
|
|
'created_from' => 'core::test',
|
|
]);
|
|
$viewer->companies()->attach($this->company->id);
|
|
$viewer->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
|
|
|
|
$this->withExceptionHandling()->loginAs($viewer)->postJson($this->statusUrl(), [
|
|
'account_short' => '测试账户',
|
|
'status' => 'limited',
|
|
])->assertForbidden();
|
|
|
|
$this->assertDatabaseCount('fin_account_statuses', 0, 'business_mirror');
|
|
}
|
|
}
|