diff --git a/src/Http/Resources/Incident.php b/src/Http/Resources/Incident.php index 777f1bda..31ae90c6 100644 --- a/src/Http/Resources/Incident.php +++ b/src/Http/Resources/Incident.php @@ -17,10 +17,12 @@ public function toAttributes(Request $request): array 'guid' => $this->guid, 'name' => $this->name, 'message' => $this->message, - 'component_id' => $this->component_id, 'visible' => $this->visible, 'stickied' => $this->stickied, 'notifications' => $this->notifications, + 'components_count' => $this->whenCounted('components', function () { + return $this->components_count; + }), 'status' => [ 'human' => $this->latestStatus?->getLabel(), 'value' => $this->latestStatus?->value, diff --git a/tests/Feature/Api/IncidentTest.php b/tests/Feature/Api/IncidentTest.php index 283df4da..d140c0e5 100644 --- a/tests/Feature/Api/IncidentTest.php +++ b/tests/Feature/Api/IncidentTest.php @@ -278,6 +278,10 @@ expect($componentBResource['attributes']['pivot']['component_status']['value']) ->toBe(ComponentStatusEnum::major_outage->value); + + // Verify the components relationship is properly returned (no component_id attribute) + expect($response->json('data.attributes'))->not->toHaveKey('component_id'); + expect($response->json('data.relationships.components.data'))->toHaveCount(2); }); it('can create an incident with a template', function () {