Add membership fee system with disability discount and fix document permissions

Features:
- Implement two fee types: entrance fee and annual fee (both NT$1,000)
- Add 50% discount for disability certificate holders
- Add disability certificate upload in member profile
- Integrate disability verification into cashier approval workflow
- Add membership fee settings in system admin

Document permissions:
- Fix hard-coded role logic in Document model
- Use permission-based authorization instead of role checks

Additional features:
- Add announcements, general ledger, and trial balance modules
- Add income management and accounting entries
- Add comprehensive test suite with factories
- Update UI translations to Traditional Chinese

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-01 09:56:01 +08:00
parent 83ce1f7fc8
commit 642b879dd4
207 changed files with 19487 additions and 3048 deletions

View File

@@ -0,0 +1,166 @@
<?php
namespace Tests\Feature\Audit;
use App\Http\Middleware\VerifyCsrfToken;
use App\Models\AuditLog;
use App\Models\Member;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
use Tests\Traits\CreatesMemberData;
use Tests\Traits\SeedsRolesAndPermissions;
/**
* Audit Log Tests
*
* Tests audit log functionality including creation and viewing.
*/
class AuditLogTest extends TestCase
{
use RefreshDatabase, SeedsRolesAndPermissions, CreatesMemberData;
protected User $admin;
protected function setUp(): void
{
parent::setUp();
Storage::fake('local');
$this->seedRolesAndPermissions();
$this->admin = $this->createAdmin();
}
/**
* Test audit log can be created
*/
public function test_audit_log_can_be_created(): void
{
$log = AuditLog::create([
'action' => 'test_action',
'user_id' => $this->admin->id,
'metadata' => ['field' => 'value'],
]);
$this->assertDatabaseHas('audit_logs', [
'action' => 'test_action',
'user_id' => $this->admin->id,
]);
}
/**
* Test audit log stores metadata
*/
public function test_audit_log_stores_metadata(): void
{
$log = AuditLog::create([
'action' => 'value_change',
'user_id' => $this->admin->id,
'metadata' => [
'old_status' => 'pending',
'new_status' => 'approved',
'ip_address' => '192.168.1.1',
],
]);
$log->refresh();
$this->assertEquals('pending', $log->metadata['old_status']);
$this->assertEquals('approved', $log->metadata['new_status']);
$this->assertEquals('192.168.1.1', $log->metadata['ip_address']);
}
/**
* Test audit log can have auditable relationship
*/
public function test_audit_log_can_have_auditable(): void
{
$member = $this->createMember();
$log = AuditLog::create([
'action' => 'member_created',
'user_id' => $this->admin->id,
'auditable_type' => Member::class,
'auditable_id' => $member->id,
]);
$this->assertEquals(Member::class, $log->auditable_type);
$this->assertEquals($member->id, $log->auditable_id);
}
/**
* Test audit log export
*/
public function test_audit_log_export(): void
{
// Create some audit logs
for ($i = 0; $i < 5; $i++) {
AuditLog::create([
'action' => "test_action_{$i}",
'user_id' => $this->admin->id,
]);
}
$response = $this->withoutMiddleware(VerifyCsrfToken::class)
->actingAs($this->admin)
->get(route('admin.audit.export'));
$response->assertStatus(200);
}
/**
* Test only admin can view audit logs
*/
public function test_only_admin_can_view_audit_logs(): void
{
$regularUser = User::factory()->create();
$response = $this->withoutMiddleware(VerifyCsrfToken::class)
->actingAs($regularUser)
->get(route('admin.audit.index'));
$response->assertForbidden();
}
/**
* Test audit log has user relationship
*/
public function test_audit_log_has_user_relationship(): void
{
$log = AuditLog::create([
'action' => 'test_action',
'user_id' => $this->admin->id,
]);
$this->assertNotNull($log->user);
$this->assertEquals($this->admin->id, $log->user->id);
}
/**
* Test audit log timestamps
*/
public function test_audit_log_has_timestamps(): void
{
$log = AuditLog::create([
'action' => 'test_action',
'user_id' => $this->admin->id,
]);
$this->assertNotNull($log->created_at);
}
/**
* Test multiple audit logs can be created
*/
public function test_multiple_audit_logs_can_be_created(): void
{
for ($i = 0; $i < 10; $i++) {
AuditLog::create([
'action' => "action_{$i}",
'user_id' => $this->admin->id,
]);
}
$this->assertCount(10, AuditLog::all());
}
}