Add Routing module: EvRoute, pricing, time slots, read API, caching (T3.1-T3.7)
Implements Phase 3 in full: EvRoute model with company/destination relations and a from/to-must-differ guard; the ev_route_time_slots pivot; RoutePricing with a per-route is_blocked flag (every route auto-manages exactly one price row per vehicle option via a fixed-row Filament repeater on both create and edit); PricingService::quote() with a shared VehicleOption enum; RoutingPlugin with the EvRouteResource admin UI (activation gated on non-blocked options being priced); the /api/v1/routes read API (list/show/pricing/time-slots, AI-agent-friendly nested shape); and Redis-tag-based response caching invalidated via EvRoute/RoutePricing observers.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Modules\Routing\Models\EvRoute;
|
||||
use Modules\Routing\Models\RoutePricing;
|
||||
use Modules\Shared\Enums\VehicleOption;
|
||||
|
||||
test('route pricing belongs to a route and casts its vehicle option, price and blocked flag', function () {
|
||||
$route = EvRoute::factory()->create();
|
||||
|
||||
$pricing = RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => VehicleOption::FrontSeat,
|
||||
'price' => 12000,
|
||||
'is_blocked' => true,
|
||||
]);
|
||||
|
||||
expect($pricing->route)->toBeInstanceOf(EvRoute::class)
|
||||
->and($pricing->route->is($route))->toBeTrue()
|
||||
->and($pricing->vehicle_option)->toBe(VehicleOption::FrontSeat)
|
||||
->and($pricing->price)->toEqual('12000.00')
|
||||
->and($pricing->is_blocked)->toBeTrue();
|
||||
|
||||
expect($route->pricing()->first()->is($pricing))->toBeTrue();
|
||||
});
|
||||
|
||||
test('a route can only have one price per vehicle option', function () {
|
||||
$route = EvRoute::factory()->create();
|
||||
|
||||
RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => VehicleOption::WholeVehicle,
|
||||
]);
|
||||
|
||||
expect(fn () => RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => VehicleOption::WholeVehicle,
|
||||
]))->toThrow(QueryException::class);
|
||||
});
|
||||
|
||||
test('a route can have all three vehicle options priced', function () {
|
||||
$route = EvRoute::factory()->create();
|
||||
|
||||
foreach (VehicleOption::cases() as $option) {
|
||||
RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => $option,
|
||||
]);
|
||||
}
|
||||
|
||||
expect($route->pricing()->count())->toBe(3);
|
||||
});
|
||||
|
||||
test('pricing defaults to unblocked', function () {
|
||||
$pricing = RoutePricing::factory()->create();
|
||||
|
||||
expect($pricing->is_blocked)->toBeFalse();
|
||||
});
|
||||
Reference in New Issue
Block a user