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,51 @@
|
||||
<?php
|
||||
|
||||
use Modules\Routing\Data\PriceQuoteData;
|
||||
use Modules\Routing\Exceptions\RoutePricingNotFoundException;
|
||||
use Modules\Routing\Models\EvRoute;
|
||||
use Modules\Routing\Models\RoutePricing;
|
||||
use Modules\Routing\Services\PricingService;
|
||||
use Modules\Shared\Enums\VehicleOption;
|
||||
|
||||
test('quote returns a price for each priced vehicle option on a route', function () {
|
||||
$route = EvRoute::factory()->create();
|
||||
|
||||
RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => VehicleOption::FrontSeat,
|
||||
'price' => 12000,
|
||||
]);
|
||||
RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => VehicleOption::BackSeat,
|
||||
'price' => 9000,
|
||||
]);
|
||||
RoutePricing::factory()->create([
|
||||
'ev_route_id' => $route->id,
|
||||
'vehicle_option' => VehicleOption::WholeVehicle,
|
||||
'price' => 30000,
|
||||
]);
|
||||
|
||||
$service = new PricingService;
|
||||
|
||||
$frontSeatQuote = $service->quote($route, VehicleOption::FrontSeat);
|
||||
$backSeatQuote = $service->quote($route, VehicleOption::BackSeat);
|
||||
$wholeVehicleQuote = $service->quote($route, VehicleOption::WholeVehicle);
|
||||
|
||||
expect($frontSeatQuote)->toBeInstanceOf(PriceQuoteData::class)
|
||||
->and($frontSeatQuote->evRouteId)->toBe($route->id)
|
||||
->and($frontSeatQuote->vehicleOption)->toBe(VehicleOption::FrontSeat)
|
||||
->and($frontSeatQuote->price)->toEqual('12000.00');
|
||||
|
||||
expect($backSeatQuote->price)->toEqual('9000.00');
|
||||
expect($wholeVehicleQuote->price)->toEqual('30000.00');
|
||||
});
|
||||
|
||||
test('quote throws when the route has no pricing for the requested vehicle option', function () {
|
||||
$route = EvRoute::factory()->create();
|
||||
|
||||
$service = new PricingService;
|
||||
|
||||
expect(fn () => $service->quote($route, VehicleOption::WholeVehicle))
|
||||
->toThrow(RoutePricingNotFoundException::class);
|
||||
});
|
||||
Reference in New Issue
Block a user