seed(DatabaseSeeder::class); $admin = User::query()->where('email', 'admin@prn.local')->firstOrFail(); $pusat = PusatMengundi::query()->where('code', 'PM001')->firstOrFail(); $this->actingAs($admin) ->post(route('admin.management.wheelchairs.store'), [ 'election_id' => $pusat->election_id, 'pusat_mengundi_id' => $pusat->id, 'allocated_quantity' => 4, 'notes' => 'Tambahan kerusi roda.', ]) ->assertRedirect(); $this->assertDatabaseHas('wheelchair_allocations', [ 'election_id' => $pusat->election_id, 'pusat_mengundi_id' => $pusat->id, 'allocated_quantity' => 4, ]); } public function test_admin_can_record_taken_and_returned_wheelchairs(): void { $this->seed(DatabaseSeeder::class); $admin = User::query()->where('email', 'admin@prn.local')->firstOrFail(); $allocation = WheelchairAllocation::query()->firstOrFail(); $allocation->update(['allocated_quantity' => 3]); $this->actingAs($admin) ->post(route('admin.management.wheelchairs.transactions.store', $allocation), [ 'transaction_type' => 'taken', 'quantity' => 2, 'taken_by_name' => 'Petugas Logistik', 'taken_at' => now()->format('Y-m-d H:i:s'), 'notes' => 'Ambil pagi.', ]) ->assertRedirect(route('admin.management.wheelchairs.show', $allocation)); $this->actingAs($admin) ->post(route('admin.management.wheelchairs.transactions.store', $allocation), [ 'transaction_type' => 'returned', 'quantity' => 1, 'returned_at' => now()->format('Y-m-d H:i:s'), 'return_condition' => 'baik', ]) ->assertRedirect(route('admin.management.wheelchairs.show', $allocation)); $this->assertDatabaseHas('wheelchair_transactions', [ 'wheelchair_allocation_id' => $allocation->id, 'transaction_type' => 'taken', 'quantity' => 2, 'taken_by_name' => 'Petugas Logistik', 'recorded_by_user_id' => $admin->id, ]); $this->assertDatabaseHas('wheelchair_transactions', [ 'wheelchair_allocation_id' => $allocation->id, 'transaction_type' => 'returned', 'quantity' => 1, 'return_condition' => 'baik', ]); } public function test_taken_quantity_cannot_exceed_available_allocation(): void { $this->seed(DatabaseSeeder::class); $admin = User::query()->where('email', 'admin@prn.local')->firstOrFail(); $allocation = WheelchairAllocation::query()->firstOrFail(); $allocation->update(['allocated_quantity' => 2]); $this->actingAs($admin) ->post(route('admin.management.wheelchairs.transactions.store', $allocation), [ 'transaction_type' => 'taken', 'quantity' => 3, 'taken_by_name' => 'Petugas Logistik', ]) ->assertSessionHasErrors('quantity'); $this->assertDatabaseMissing('wheelchair_transactions', [ 'wheelchair_allocation_id' => $allocation->id, 'quantity' => 3, ]); } public function test_return_quantity_cannot_exceed_outstanding_quantity(): void { $this->seed(DatabaseSeeder::class); $admin = User::query()->where('email', 'admin@prn.local')->firstOrFail(); $allocation = WheelchairAllocation::query()->firstOrFail(); $allocation->update(['allocated_quantity' => 2]); WheelchairTransaction::query()->create([ 'wheelchair_allocation_id' => $allocation->id, 'transaction_type' => 'taken', 'quantity' => 1, 'taken_at' => now(), 'taken_by_name' => 'Petugas Logistik', 'recorded_by_user_id' => $admin->id, ]); $this->actingAs($admin) ->post(route('admin.management.wheelchairs.transactions.store', $allocation), [ 'transaction_type' => 'returned', 'quantity' => 2, 'return_condition' => 'baik', ]) ->assertSessionHasErrors('quantity'); } public function test_allocation_cannot_be_reduced_below_outstanding_quantity(): void { $this->seed(DatabaseSeeder::class); $admin = User::query()->where('email', 'admin@prn.local')->firstOrFail(); $allocation = WheelchairAllocation::query()->firstOrFail(); $allocation->update(['allocated_quantity' => 3]); WheelchairTransaction::query()->create([ 'wheelchair_allocation_id' => $allocation->id, 'transaction_type' => 'taken', 'quantity' => 2, 'taken_at' => now(), 'taken_by_name' => 'Petugas Logistik', 'recorded_by_user_id' => $admin->id, ]); $this->actingAs($admin) ->patch(route('admin.management.wheelchairs.update', $allocation), [ 'election_id' => $allocation->election_id, 'pusat_mengundi_id' => $allocation->pusat_mengundi_id, 'allocated_quantity' => 1, ]) ->assertSessionHasErrors('allocated_quantity'); } public function test_admin_kewangan_cannot_manage_wheelchairs(): void { $this->seed(DatabaseSeeder::class); $finance = User::query()->where('email', 'kewangan@prn.local')->firstOrFail(); $this->actingAs($finance) ->get(route('admin.management.wheelchairs.index')) ->assertForbidden(); } }