4da9ecfe7d
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.
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?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();
|
|
});
|