1. API docs via dedoc/scramble at /docs/api (scoped to api/v1).
Linked from the admin sidebar Settings group.
2. Scheduled commands registered in routes/console.php:
- reports:aggregate (02:00) — daily/weekly/monthly aggregations
- qr:expire (02:30) — flips past-due allocated/active codes to expired
- trucks:prune-locations (03:00) — drops history older than retention
window (default 7 days, config('verde.location_retention_days'))
All idempotent + withoutOverlapping. --dry flags on qr:expire and
trucks:prune-locations for safe inspection.
3. Trip double-booking validation: AdminTripController::store rejects
new trips when the team or truck already has a non-cancelled trip on
the same date. override_conflicts: true bypasses for emergencies.
Cancelled trips don't block rebooking.
4a. Email verification: User implements MustVerifyEmail.
VerifyEmailNotification overrides verificationUrl() for our
namespaced route. Register sends the link automatically (best
effort, won't block signup). POST /auth/email/resend (auth) +
GET /auth/email/verify/{id}/{hash} (signed URL).
4b. Password change while logged in: POST /me/password validates
current_password, requires the new password to differ, revokes
every other active token on success — current session stays.
5a. PickupImminent notification: when TripStop -> arrived,
TripExecutor::notifyAssignedHouseholds() finds households whose
assigned_drop_off_point_id matches and sends DB + SMS.
5b. Auto-geofence on truck location: TruckTracker::record() now
auto-fires TripExecutor::arriveAtDumpsite() when an in-progress
trip's truck pings inside its dumpsite boundary. The executor's
status guard prevents duplicate timeline events if the driver also
presses arrive-dumpsite manually.
190 feature tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.8 KiB
PHP
73 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\V1\Notification;
|
|
|
|
use App\Models\CollectionTeam;
|
|
use App\Models\DropOffPoint;
|
|
use App\Models\Household;
|
|
use App\Models\Route;
|
|
use App\Models\RouteStop;
|
|
use App\Models\Trip;
|
|
use App\Models\TripStop;
|
|
use App\Models\User;
|
|
use App\Notifications\PickupImminent;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Database\Seeders\SampleDropOffPointsSeeder;
|
|
use Database\Seeders\SamplePsgcSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class PickupImminentTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_notifies_assigned_households_when_truck_arrives_at_their_dop(): void
|
|
{
|
|
$this->seed([RoleSeeder::class, SamplePsgcSeeder::class, SampleDropOffPointsSeeder::class]);
|
|
Notification::fake();
|
|
|
|
$driver = User::factory()->create(['role' => User::ROLE_DRIVER, 'status' => 'active']);
|
|
$resident = User::factory()->create(['role' => User::ROLE_RESIDENT, 'status' => 'active']);
|
|
$otherResident = User::factory()->create(['role' => User::ROLE_RESIDENT, 'status' => 'active']);
|
|
|
|
$dop = DropOffPoint::where('code', 'DOP-QC-DLM-01')->firstOrFail();
|
|
$otherDop = DropOffPoint::where('code', 'DOP-QC-CMW-01')->firstOrFail();
|
|
|
|
// Resident's household assigned to this DOP — should be notified
|
|
Household::factory()->create([
|
|
'head_user_id' => $resident->id,
|
|
'assigned_drop_off_point_id' => $dop->id,
|
|
]);
|
|
// Other household assigned to a different DOP — should NOT be notified
|
|
Household::factory()->create([
|
|
'head_user_id' => $otherResident->id,
|
|
'assigned_drop_off_point_id' => $otherDop->id,
|
|
]);
|
|
|
|
$team = CollectionTeam::create([
|
|
'name' => 'TX', 'driver_id' => $driver->id, 'status' => 'active',
|
|
]);
|
|
$route = Route::create(['name' => 'R', 'code' => 'RT-PI', 'status' => 'active']);
|
|
RouteStop::create(['route_id' => $route->id, 'drop_off_point_id' => $dop->id, 'sequence' => 1]);
|
|
$trip = Trip::create([
|
|
'trip_number' => 'TRIP-PI', 'route_id' => $route->id, 'team_id' => $team->id,
|
|
'scheduled_date' => now()->toDateString(), 'status' => 'in_progress',
|
|
'actual_start_time' => now(),
|
|
]);
|
|
$stop = TripStop::create([
|
|
'trip_id' => $trip->id, 'drop_off_point_id' => $dop->id, 'sequence' => 1, 'status' => 'pending',
|
|
]);
|
|
|
|
Sanctum::actingAs($driver);
|
|
|
|
$this->postJson("/api/v1/driver/trips/{$trip->uuid}/stops/{$stop->id}/arrive", [
|
|
'lat' => 14.6539, 'lng' => 121.0685,
|
|
])->assertOk();
|
|
|
|
Notification::assertSentTo($resident, PickupImminent::class);
|
|
Notification::assertNotSentTo($otherResident, PickupImminent::class);
|
|
}
|
|
}
|