- **Sentry** wired in bootstrap/app.php via Sentry\Laravel\Integration.
No-op when SENTRY_LARAVEL_DSN is empty.
- **Audit logging** broadened: LogsActivity applied to Household, QrCode,
Trip, Payment with tight logOnly whitelists and named log channels
('household', 'qr_code', 'trip', 'payment') to keep the activity
stream useful.
- **Bulk admin actions**:
POST /admin/households/bulk-approve — skips already-approved /
no-proof / unknown ids, reports per-id outcomes
POST /admin/bulk/users/{suspend,activate} — admins protected
POST /admin/bulk/qr-codes/void — respects state machine transitions
- **FCM push scaffold**: PushDriver contract with LogPushDriver
(default) and FcmPushDriver (activates when FCM_SERVER_KEY is set).
PushChannel adapts notifications. RoutesByPreferences now also
routes via push when push_enabled + fcm_token. toPush() payloads
added to HouseholdApproved / QrBalanceLow / PickupImminent.
- **Reverb WebSocket broadcast**: laravel/reverb installed.
TruckLocationBroadcast fires on every TruckTracker::record().
routes/channels.php authenticates: admins → private-admin.live,
residents → area.{id}.trucks (only if their household barangay is
covered by the service area).
- **PSGC seeder** expanded: all 17 PH regions, 4 NCR districts,
all 17 NCR cities. Sample barangays still carry rectangular
boundaries for point-in-polygon resolution tests.
- **Conditional SPATIAL INDEX migration** for barangays.boundary —
safe no-op until every row has a polygon (i.e., after full PSA
dataset import). Re-running `php artisan migrate` after import
flips the column to NOT NULL and adds the index.
196 feature tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
78 lines
2.7 KiB
PHP
78 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\V1\Admin;
|
|
|
|
use App\Models\Household;
|
|
use App\Models\QrCode;
|
|
use App\Models\QrCodeBatch;
|
|
use App\Models\User;
|
|
use App\Services\Qr\BatchGenerator;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class BulkActionsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $admin;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
$this->admin = User::factory()->create(['role' => User::ROLE_ADMIN, 'status' => 'active']);
|
|
}
|
|
|
|
public function test_bulk_approve_only_approves_eligible_households(): void
|
|
{
|
|
Sanctum::actingAs($this->admin);
|
|
|
|
$a = Household::factory()->create(['verification_status' => 'pending', 'proof_of_residency_path' => 'a.jpg']);
|
|
$b = Household::factory()->create(['verification_status' => 'pending', 'proof_of_residency_path' => null]);
|
|
$c = Household::factory()->create(['verification_status' => 'approved', 'proof_of_residency_path' => 'c.jpg']);
|
|
|
|
$response = $this->postJson('/api/v1/admin/households/bulk-approve', [
|
|
'household_ids' => [$a->uuid, $b->uuid, $c->uuid],
|
|
]);
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('data.approved', 1)
|
|
->assertJsonPath('data.rejected', 2);
|
|
|
|
$this->assertSame('approved', $a->fresh()->verification_status);
|
|
$this->assertSame('pending', $b->fresh()->verification_status);
|
|
}
|
|
|
|
public function test_bulk_suspend_users_skips_admins(): void
|
|
{
|
|
Sanctum::actingAs($this->admin);
|
|
$resident = User::factory()->create(['role' => User::ROLE_RESIDENT, 'status' => 'active']);
|
|
$otherAdmin = User::factory()->create(['role' => User::ROLE_ADMIN, 'status' => 'active']);
|
|
|
|
$response = $this->postJson('/api/v1/admin/bulk/users/suspend', [
|
|
'user_ids' => [$resident->uuid, $otherAdmin->uuid],
|
|
]);
|
|
|
|
$response->assertOk()->assertJsonPath('data.suspended', 1);
|
|
$this->assertSame('suspended', $resident->fresh()->status);
|
|
$this->assertSame('active', $otherAdmin->fresh()->status);
|
|
}
|
|
|
|
public function test_bulk_void_qr_codes_with_reason(): void
|
|
{
|
|
Sanctum::actingAs($this->admin);
|
|
$batch = app(BatchGenerator::class)->generate(3, QrCodeBatch::PURPOSE_FREE);
|
|
$serials = $batch->codes->pluck('serial')->all();
|
|
|
|
$response = $this->postJson('/api/v1/admin/bulk/qr-codes/void', [
|
|
'serials' => $serials,
|
|
'reason' => 'Misprint batch',
|
|
]);
|
|
|
|
$response->assertOk()->assertJsonPath('data.voided', 3);
|
|
$this->assertSame(3, QrCode::where('status', 'voided')->count());
|
|
}
|
|
}
|