Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow deleted measures to be retrieved from the plugin api #395

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Http/Controllers/PluginApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\FlightInformationRegion;
use App\Repository\FlowMeasureRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PluginApiController
{
Expand All @@ -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(
[
Expand All @@ -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')
),
]
);
Expand Down
49 changes: 49 additions & 0 deletions tests/Api/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]
);
}
}