52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
|
|
<?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);
|
||
|
|
});
|