Skip to content

Commit c7232fd

Browse files
Set incident status to fixed when incident update status is fixed (#349)
1 parent 7b81873 commit c7232fd

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Actions/Update/CreateUpdate.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function handle(Incident|Schedule $resource, CreateIncidentUpdateRequestD
2222
$resource->updates()->save($update);
2323

2424
if ($resource instanceof Incident && $data->status === IncidentStatusEnum::fixed) {
25+
$resource->update(['status' => IncidentStatusEnum::fixed]);
2526
$this->updateComponentsToOperational($resource);
2627
}
2728

tests/Unit/Actions/Update/CreateUpdateTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,38 @@
4141
->latestStatus->toEqual(IncidentStatusEnum::identified);
4242
});
4343

44+
it('transitions parent incident status to fixed when incident update status is fixed', function () {
45+
$incident = Incident::factory()->create([
46+
'status' => IncidentStatusEnum::investigating,
47+
]);
48+
49+
$data = CreateIncidentUpdateRequestData::from([
50+
'message' => 'This issue has been fixed.',
51+
'status' => IncidentStatusEnum::fixed,
52+
]);
53+
54+
app(CreateUpdate::class)->handle($incident, $data);
55+
56+
expect($incident->fresh())
57+
->status->toEqual(IncidentStatusEnum::fixed);
58+
});
59+
60+
it('does not change parent incident status when incident update status is not fixed', function () {
61+
$incident = Incident::factory()->create([
62+
'status' => IncidentStatusEnum::investigating,
63+
]);
64+
65+
$data = CreateIncidentUpdateRequestData::from([
66+
'message' => 'Still looking into this.',
67+
'status' => IncidentStatusEnum::identified,
68+
]);
69+
70+
app(CreateUpdate::class)->handle($incident, $data);
71+
72+
expect($incident->fresh())
73+
->status->toEqual(IncidentStatusEnum::investigating);
74+
});
75+
4476
it('sets linked component status to operational when incident update status is fixed', function () {
4577
$incident = Incident::factory()->create([
4678
'status' => IncidentStatusEnum::investigating,

0 commit comments

Comments
 (0)