Skip to content

Commit 2d0a01b

Browse files
authored
Remove misleading component_id from Incident resource (#314)
1 parent 4cdcaa6 commit 2d0a01b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Http/Resources/Incident.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ public function toAttributes(Request $request): array
1717
'guid' => $this->guid,
1818
'name' => $this->name,
1919
'message' => $this->message,
20-
'component_id' => $this->component_id,
2120
'visible' => $this->visible,
2221
'stickied' => $this->stickied,
2322
'notifications' => $this->notifications,
23+
'components_count' => $this->whenCounted('components', function () {
24+
return $this->components_count;
25+
}),
2426
'status' => [
2527
'human' => $this->latestStatus?->getLabel(),
2628
'value' => $this->latestStatus?->value,

tests/Feature/Api/IncidentTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@
278278

279279
expect($componentBResource['attributes']['pivot']['component_status']['value'])
280280
->toBe(ComponentStatusEnum::major_outage->value);
281+
282+
// Verify the components relationship is properly returned (no component_id attribute)
283+
expect($response->json('data.attributes'))->not->toHaveKey('component_id');
284+
expect($response->json('data.relationships.components.data'))->toHaveCount(2);
281285
});
282286

283287
it('can create an incident with a template', function () {

0 commit comments

Comments
 (0)