Skip to content
Open
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
1 change: 1 addition & 0 deletions src/Http/Controllers/Api/IncidentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class IncidentController extends Controller
*/
public const ALLOWED_INCLUDES = [
'components',
'components.group',
'updates',
'user',
];
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Api/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ScheduleController extends Controller
public function index()
{
$schedules = QueryBuilder::for(Schedule::class)
->allowedIncludes(['components', 'updates', 'user'])
->allowedIncludes(['components', 'components.group', 'updates', 'user'])
->allowedFilters(['name', AllowedFilter::custom('status', new ScheduleStatusFilter)])
->allowedSorts(['name', 'id', 'scheduled_at', 'completed_at'])
->simplePaginate(request('per_page', 15));
Expand All @@ -60,7 +60,7 @@ public function store(CreateScheduleRequestData $data, CreateSchedule $createSch
public function show(Schedule $schedule)
{
$scheduleQuery = QueryBuilder::for(Schedule::class)
->allowedIncludes(['components', 'updates', 'user'])
->allowedIncludes(['components', 'components.group', 'updates', 'user'])
->find($schedule->id);

return ScheduleResource::make($scheduleQuery)
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/Api/IncidentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Cachet\Enums\ComponentStatusEnum;
use Cachet\Enums\IncidentStatusEnum;
use Cachet\Models\Component;
use Cachet\Models\ComponentGroup;
use Cachet\Models\Incident;
use Cachet\Models\IncidentTemplate;
use Laravel\Sanctum\Sanctum;
Expand Down Expand Up @@ -188,6 +189,22 @@
]);
});

it('can get an incident with components and their groups', function () {
$group = ComponentGroup::factory()->create();
$component = Component::factory()->for($group, 'group')->create();
$incident = Incident::factory()->create();
$incident->components()->attach($component, ['component_status' => ComponentStatusEnum::partial_outage->value]);

$response = getJson('/status/api/incidents/'.$incident->id.'?include=components.group');

$response->assertOk();

$included = collect($response->json('included'));

expect($included->firstWhere('id', (string) $component->id))->not->toBeNull()
->and($included->firstWhere('attributes.name', $group->name))->not->toBeNull();
});

it('cannot create an incident if not authenticated', function () {
$response = postJson('/status/api/incidents', [
'name' => 'New Incident Occurred',
Expand Down
18 changes: 18 additions & 0 deletions tests/Feature/Api/ScheduleTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use Cachet\Enums\ComponentStatusEnum;
use Cachet\Enums\ScheduleStatusEnum;
use Cachet\Models\Component;
use Cachet\Models\ComponentGroup;
use Cachet\Models\Schedule;
use Laravel\Sanctum\Sanctum;
use Workbench\App\User;
Expand Down Expand Up @@ -195,6 +197,22 @@
]);
});

it('can get a schedule with components and their groups', function () {
$group = ComponentGroup::factory()->create();
$component = Component::factory()->for($group, 'group')->create();
$schedule = Schedule::factory()->create();
$schedule->components()->attach($component, ['component_status' => ComponentStatusEnum::partial_outage->value]);

$response = getJson('/status/api/schedules/'.$schedule->id.'?include=components.group');

$response->assertOk();

$included = collect($response->json('included'));

expect($included->firstWhere('id', (string) $component->id))->not->toBeNull()
->and($included->firstWhere('attributes.name', $group->name))->not->toBeNull();
});

it('cannot create a schedule if not authenticated', function () {
$response = postJson('/status/api/schedules', [
'name' => 'New Scheduled Maintenance',
Expand Down
Loading