From 20c30efaf37ae21d2ec29d5b6567212cf8c69106 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Fri, 18 Aug 2023 18:11:27 +0100 Subject: [PATCH] feat: allow deleted measures to be retrieved from the plugin api --- app/Http/Controllers/PluginApiController.php | 5 +- tests/Api/PluginTest.php | 49 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) 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..b4d0ba7e 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])->get() + )->toArray(new Request()), + ] + ); + } }