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:
109
tests/Feature/Validation/FinanceDocumentValidationTest.php
Normal file
109
tests/Feature/Validation/FinanceDocumentValidationTest.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Validation;
|
||||
|
||||
use App\Http\Middleware\VerifyCsrfToken;
|
||||
use App\Models\FinanceDocument;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CreatesFinanceData;
|
||||
use Tests\Traits\SeedsRolesAndPermissions;
|
||||
|
||||
/**
|
||||
* Finance Document Validation Tests
|
||||
*
|
||||
* Tests finance document model behavior and amount tiers.
|
||||
*/
|
||||
class FinanceDocumentValidationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, SeedsRolesAndPermissions, CreatesFinanceData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Storage::fake('local');
|
||||
$this->seedRolesAndPermissions();
|
||||
}
|
||||
|
||||
public function test_amount_tier_small(): void
|
||||
{
|
||||
$document = $this->createFinanceDocument(['amount' => 3000]);
|
||||
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_SMALL, $document->determineAmountTier());
|
||||
}
|
||||
|
||||
public function test_amount_tier_medium(): void
|
||||
{
|
||||
$document = $this->createFinanceDocument(['amount' => 25000]);
|
||||
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_MEDIUM, $document->determineAmountTier());
|
||||
}
|
||||
|
||||
public function test_amount_tier_large(): void
|
||||
{
|
||||
$document = $this->createFinanceDocument(['amount' => 75000]);
|
||||
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_LARGE, $document->determineAmountTier());
|
||||
}
|
||||
|
||||
public function test_document_amount_boundary_small_medium(): void
|
||||
{
|
||||
// 4999 should be small
|
||||
$smallDoc = $this->createFinanceDocument(['amount' => 4999]);
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_SMALL, $smallDoc->determineAmountTier());
|
||||
|
||||
// 5000 should be medium
|
||||
$mediumDoc = $this->createFinanceDocument(['amount' => 5000]);
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_MEDIUM, $mediumDoc->determineAmountTier());
|
||||
}
|
||||
|
||||
public function test_document_amount_boundary_medium_large(): void
|
||||
{
|
||||
// 50000 should be medium
|
||||
$mediumDoc = $this->createFinanceDocument(['amount' => 50000]);
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_MEDIUM, $mediumDoc->determineAmountTier());
|
||||
|
||||
// 50001 should be large
|
||||
$largeDoc = $this->createFinanceDocument(['amount' => 50001]);
|
||||
$this->assertEquals(FinanceDocument::AMOUNT_TIER_LARGE, $largeDoc->determineAmountTier());
|
||||
}
|
||||
|
||||
public function test_document_status_constants(): void
|
||||
{
|
||||
$this->assertEquals('pending', FinanceDocument::STATUS_PENDING);
|
||||
$this->assertEquals('approved_cashier', FinanceDocument::STATUS_APPROVED_CASHIER);
|
||||
$this->assertEquals('approved_accountant', FinanceDocument::STATUS_APPROVED_ACCOUNTANT);
|
||||
$this->assertEquals('approved_chair', FinanceDocument::STATUS_APPROVED_CHAIR);
|
||||
$this->assertEquals('rejected', FinanceDocument::STATUS_REJECTED);
|
||||
}
|
||||
|
||||
public function test_cashier_can_approve_pending_document(): void
|
||||
{
|
||||
$cashier = $this->createCashier();
|
||||
$document = $this->createFinanceDocument(['status' => FinanceDocument::STATUS_PENDING]);
|
||||
|
||||
$response = $this->withoutMiddleware(VerifyCsrfToken::class)
|
||||
->actingAs($cashier)
|
||||
->post(route('admin.finance.approve', $document));
|
||||
|
||||
$document->refresh();
|
||||
$this->assertEquals(FinanceDocument::STATUS_APPROVED_CASHIER, $document->status);
|
||||
}
|
||||
|
||||
public function test_cashier_can_reject_pending_document(): void
|
||||
{
|
||||
$cashier = $this->createCashier();
|
||||
$document = $this->createFinanceDocument(['status' => FinanceDocument::STATUS_PENDING]);
|
||||
|
||||
$response = $this->withoutMiddleware(VerifyCsrfToken::class)
|
||||
->actingAs($cashier)
|
||||
->post(
|
||||
route('admin.finance.reject', $document),
|
||||
['rejection_reason' => 'Test rejection']
|
||||
);
|
||||
|
||||
$document->refresh();
|
||||
$this->assertEquals(FinanceDocument::STATUS_REJECTED, $document->status);
|
||||
}
|
||||
}
|
||||
145
tests/Feature/Validation/IssueValidationTest.php
Normal file
145
tests/Feature/Validation/IssueValidationTest.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Validation;
|
||||
|
||||
use App\Models\Issue;
|
||||
use App\Models\IssueComment;
|
||||
use App\Models\IssueLabel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\SeedsRolesAndPermissions;
|
||||
|
||||
/**
|
||||
* Issue Validation Tests
|
||||
*
|
||||
* Tests validation rules and model behavior for issue tracking functionality.
|
||||
*/
|
||||
class IssueValidationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, SeedsRolesAndPermissions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seedRolesAndPermissions();
|
||||
}
|
||||
|
||||
public function test_issue_number_is_generated(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
$issue = Issue::factory()->create(['created_by_user_id' => $admin->id]);
|
||||
|
||||
$this->assertNotEmpty($issue->issue_number);
|
||||
$this->assertMatchesRegularExpression('/^ISS-\d{4}-\d+$/', $issue->issue_number);
|
||||
}
|
||||
|
||||
public function test_issue_defaults_to_new_status(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
$issue = Issue::factory()->create(['created_by_user_id' => $admin->id]);
|
||||
|
||||
$this->assertEquals(Issue::STATUS_NEW, $issue->status);
|
||||
}
|
||||
|
||||
public function test_issue_can_have_assignee(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
$assignee = $this->createAdmin();
|
||||
|
||||
$issue = Issue::factory()->create([
|
||||
'created_by_user_id' => $admin->id,
|
||||
'assigned_to_user_id' => $assignee->id,
|
||||
]);
|
||||
|
||||
$this->assertEquals($assignee->id, $issue->assigned_to_user_id);
|
||||
$this->assertEquals($assignee->id, $issue->assignee->id);
|
||||
}
|
||||
|
||||
public function test_issue_can_have_due_date(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
$dueDate = now()->addWeek();
|
||||
|
||||
$issue = Issue::factory()->create([
|
||||
'created_by_user_id' => $admin->id,
|
||||
'due_date' => $dueDate,
|
||||
]);
|
||||
|
||||
$this->assertTrue($issue->due_date->isSameDay($dueDate));
|
||||
}
|
||||
|
||||
public function test_issue_can_have_parent(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
|
||||
$parentIssue = Issue::factory()->create(['created_by_user_id' => $admin->id]);
|
||||
$childIssue = Issue::factory()->create([
|
||||
'created_by_user_id' => $admin->id,
|
||||
'parent_issue_id' => $parentIssue->id,
|
||||
]);
|
||||
|
||||
$this->assertEquals($parentIssue->id, $childIssue->parent_issue_id);
|
||||
$this->assertEquals($parentIssue->id, $childIssue->parentIssue->id);
|
||||
}
|
||||
|
||||
public function test_issue_can_have_subtasks(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
|
||||
$parentIssue = Issue::factory()->create(['created_by_user_id' => $admin->id]);
|
||||
|
||||
Issue::factory()->count(3)->create([
|
||||
'created_by_user_id' => $admin->id,
|
||||
'parent_issue_id' => $parentIssue->id,
|
||||
]);
|
||||
|
||||
$this->assertCount(3, $parentIssue->subTasks);
|
||||
}
|
||||
|
||||
public function test_issue_can_have_comments(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
$issue = Issue::factory()->create(['created_by_user_id' => $admin->id]);
|
||||
|
||||
IssueComment::factory()->count(5)->create([
|
||||
'issue_id' => $issue->id,
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
|
||||
$this->assertCount(5, $issue->comments);
|
||||
}
|
||||
|
||||
public function test_issue_can_have_labels(): void
|
||||
{
|
||||
$admin = $this->createAdmin();
|
||||
$issue = Issue::factory()->create(['created_by_user_id' => $admin->id]);
|
||||
$labels = IssueLabel::factory()->count(3)->create();
|
||||
|
||||
$issue->labels()->attach($labels->pluck('id'));
|
||||
|
||||
$this->assertCount(3, $issue->labels);
|
||||
}
|
||||
|
||||
public function test_issue_status_constants(): void
|
||||
{
|
||||
$this->assertEquals('new', Issue::STATUS_NEW);
|
||||
$this->assertEquals('in_progress', Issue::STATUS_IN_PROGRESS);
|
||||
$this->assertEquals('closed', Issue::STATUS_CLOSED);
|
||||
}
|
||||
|
||||
public function test_issue_priority_constants(): void
|
||||
{
|
||||
$this->assertEquals('low', Issue::PRIORITY_LOW);
|
||||
$this->assertEquals('medium', Issue::PRIORITY_MEDIUM);
|
||||
$this->assertEquals('high', Issue::PRIORITY_HIGH);
|
||||
$this->assertEquals('urgent', Issue::PRIORITY_URGENT);
|
||||
}
|
||||
|
||||
public function test_issue_type_constants(): void
|
||||
{
|
||||
$this->assertEquals('work_item', Issue::TYPE_WORK_ITEM);
|
||||
$this->assertEquals('project_task', Issue::TYPE_PROJECT_TASK);
|
||||
$this->assertEquals('maintenance', Issue::TYPE_MAINTENANCE);
|
||||
$this->assertEquals('member_request', Issue::TYPE_MEMBER_REQUEST);
|
||||
}
|
||||
}
|
||||
120
tests/Feature/Validation/MemberValidationTest.php
Normal file
120
tests/Feature/Validation/MemberValidationTest.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Validation;
|
||||
|
||||
use App\Http\Middleware\VerifyCsrfToken;
|
||||
use App\Models\Member;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
use Tests\Traits\CreatesMemberData;
|
||||
use Tests\Traits\SeedsRolesAndPermissions;
|
||||
|
||||
/**
|
||||
* Member Validation Tests
|
||||
*
|
||||
* Tests validation rules for member registration and model behavior.
|
||||
*/
|
||||
class MemberValidationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, SeedsRolesAndPermissions, CreatesMemberData;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Mail::fake();
|
||||
$this->seedRolesAndPermissions();
|
||||
}
|
||||
|
||||
public function test_member_can_be_created(): void
|
||||
{
|
||||
$member = $this->createMember(['full_name' => 'Test Member']);
|
||||
|
||||
$this->assertDatabaseHas('members', ['full_name' => 'Test Member']);
|
||||
}
|
||||
|
||||
public function test_member_defaults_to_pending_status(): void
|
||||
{
|
||||
$member = $this->createPendingMember();
|
||||
|
||||
$this->assertEquals(Member::STATUS_PENDING, $member->membership_status);
|
||||
}
|
||||
|
||||
public function test_member_can_be_activated(): void
|
||||
{
|
||||
$member = $this->createActiveMember();
|
||||
|
||||
$this->assertEquals(Member::STATUS_ACTIVE, $member->membership_status);
|
||||
}
|
||||
|
||||
public function test_member_can_be_expired(): void
|
||||
{
|
||||
$member = $this->createExpiredMember();
|
||||
|
||||
$this->assertEquals(Member::STATUS_EXPIRED, $member->membership_status);
|
||||
}
|
||||
|
||||
public function test_member_has_user_relationship(): void
|
||||
{
|
||||
$member = $this->createMember();
|
||||
|
||||
$this->assertNotNull($member->user);
|
||||
$this->assertInstanceOf(User::class, $member->user);
|
||||
}
|
||||
|
||||
public function test_email_uniqueness_in_users_table(): void
|
||||
{
|
||||
User::factory()->create(['email' => 'existing@example.com']);
|
||||
|
||||
$data = $this->getValidMemberRegistrationData(['email' => 'existing@example.com']);
|
||||
$response = $this->withoutMiddleware(VerifyCsrfToken::class)
|
||||
->post(route('register.member.store'), $data);
|
||||
|
||||
$response->assertSessionHasErrors('email');
|
||||
}
|
||||
|
||||
public function test_email_uniqueness_in_members_table(): void
|
||||
{
|
||||
$existingMember = $this->createMember(['email' => 'member@example.com']);
|
||||
|
||||
$data = $this->getValidMemberRegistrationData(['email' => 'member@example.com']);
|
||||
$response = $this->withoutMiddleware(VerifyCsrfToken::class)
|
||||
->post(route('register.member.store'), $data);
|
||||
|
||||
$response->assertSessionHasErrors('email');
|
||||
}
|
||||
|
||||
public function test_membership_payment_can_be_created(): void
|
||||
{
|
||||
$data = $this->createMemberWithPendingPayment();
|
||||
|
||||
$this->assertNotNull($data['payment']);
|
||||
$this->assertEquals($data['member']->id, $data['payment']->member_id);
|
||||
}
|
||||
|
||||
public function test_members_have_unique_ids(): void
|
||||
{
|
||||
$member1 = $this->createMember();
|
||||
$member2 = $this->createMember();
|
||||
|
||||
$this->assertNotEquals($member1->id, $member2->id);
|
||||
}
|
||||
|
||||
public function test_active_member_has_paid_membership(): void
|
||||
{
|
||||
$member = $this->createActiveMember([
|
||||
'membership_started_at' => now()->subMonth(),
|
||||
'membership_expires_at' => now()->addYear(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($member->hasPaidMembership());
|
||||
}
|
||||
|
||||
public function test_pending_member_does_not_have_paid_membership(): void
|
||||
{
|
||||
$member = $this->createPendingMember();
|
||||
|
||||
$this->assertFalse($member->hasPaidMembership());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user