diff --git a/app/Http/Controllers/PluginApiController.php b/app/Http/Controllers/PluginApiController.php index 0b75e4cc..390cb8b5 100644 --- a/app/Http/Controllers/PluginApiController.php +++ b/app/Http/Controllers/PluginApiController.php @@ -9,6 +9,7 @@ use App\Models\FlightInformationRegion; use App\Repository\FlowMeasureRepository; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class PluginApiController { @@ -19,7 +20,7 @@ public function __construct(FlowMeasureRepository $flowMeasureRepository) $this->flowMeasureRepository = $flowMeasureRepository; } - public function __invoke(): JsonResponse + public function __invoke(Request $request): JsonResponse { return response()->json( [ @@ -28,7 +29,7 @@ public function __invoke(): JsonResponse FlightInformationRegion::all() ), 'flow_measures' => FlowMeasureResource::collection( - $this->flowMeasureRepository->getApiRelevantFlowMeasures(false) + $this->flowMeasureRepository->getApiRelevantFlowMeasures($request->query('deleted', '0') === '1') ), ] ); diff --git a/tests/Api/PluginTest.php b/tests/Api/PluginTest.php index 70a540d3..d1c82224 100644 --- a/tests/Api/PluginTest.php +++ b/tests/Api/PluginTest.php @@ -75,4 +75,53 @@ public function testItReturnsPluginApiData() ] ); } + + public function testItReturnsPluginApiDataWithDeleted() + { + FlightInformationRegion::factory()->count(5)->create(); + Event::factory()->count(3)->create(); + + // Should show + $active = FlowMeasure::factory() + ->create(); + + $notStarted = FlowMeasure::factory() + ->notStarted() + ->create(); + + $finished = FlowMeasure::factory() + ->finished() + ->create(); + + // Should show, deleted + $deleted = FlowMeasure::factory() + ->create(); + $deleted->delete(); + + // Shouldn't show, too far in the future + FlowMeasure::factory() + ->withTimes(Carbon::now()->addDay()->addHour(), Carbon::now()->addDay()->addHours(2)) + ->withEvent() + ->create(); + + // Shouldn't show, too far in the past + FlowMeasure::factory() + ->withTimes(Carbon::now()->subDay()->subHours(3), Carbon::now()->subDay()->subHours(2)) + ->withEvent() + ->create(); + + $this->get('api/v1/plugin?deleted=1') + ->assertStatus(200) + ->assertExactJson( + [ + 'events' => EventResource::collection(Event::all())->toArray(new Request()), + 'flight_information_regions' => FlightInformationRegionResource::collection( + FlightInformationRegion::all() + )->toArray(new Request()), + 'flow_measures' => FlowMeasureResource::collection( + FlowMeasure::whereIn('id', [$active->id, $notStarted->id, $finished->id, $deleted->id])->withTrashed()->get() + )->toArray(new Request()), + ] + ); + } }