Skip to content

Commit 35b1f34

Browse files
Copilotjbrooksuk
andauthored
Exclude disabled components from system status calculation (#329)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com>
1 parent d7b9720 commit 35b1f34

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/Status.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function components(): object
7878
{
7979
return $this->components ??= Component::query()
8080
->toBase()
81+
->where('enabled', true)
8182
->selectRaw('count(*) as total')
8283
->selectRaw('sum(case when status = ? then 1 else 0 end) as operational', [ComponentStatusEnum::operational])
8384
->selectRaw('sum(case when status = ? then 1 else 0 end) as performance_issues', [ComponentStatusEnum::performance_issues])

tests/Unit/StatusTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,66 @@
9696
->major_outage->toBe(1)
9797
->under_maintenance->toBe(1);
9898
});
99+
100+
it('excludes disabled components from component overview', function () {
101+
Component::factory()->create([
102+
'status' => ComponentStatusEnum::operational->value,
103+
'enabled' => true,
104+
]);
105+
106+
Component::factory()->create([
107+
'status' => ComponentStatusEnum::major_outage->value,
108+
'enabled' => false,
109+
]);
110+
111+
$components = (new Status)->components();
112+
113+
expect($components)
114+
->total->toBe(1)
115+
->operational->toBe(1)
116+
->major_outage->toBe(0);
117+
});
118+
119+
it('excludes disabled components from system status calculation', function () {
120+
Component::factory()->create([
121+
'status' => ComponentStatusEnum::operational->value,
122+
'enabled' => true,
123+
]);
124+
125+
Component::factory()->create([
126+
'status' => ComponentStatusEnum::partial_outage->value,
127+
'enabled' => false,
128+
]);
129+
130+
$this->assertEquals((new Status)->current(), SystemStatusEnum::operational);
131+
});
132+
133+
it('excludes disabled components from major outage calculation', function () {
134+
$status = new Status;
135+
136+
Component::factory()->create([
137+
'status' => ComponentStatusEnum::major_outage->value,
138+
'enabled' => false,
139+
]);
140+
141+
Component::factory()->create([
142+
'status' => ComponentStatusEnum::operational->value,
143+
'enabled' => true,
144+
]);
145+
146+
assertFalse($status->majorOutage());
147+
});
148+
149+
it('excludes disabled components from under maintenance status', function () {
150+
Component::factory()->create([
151+
'status' => ComponentStatusEnum::under_maintenance->value,
152+
'enabled' => false,
153+
]);
154+
155+
Component::factory()->create([
156+
'status' => ComponentStatusEnum::operational->value,
157+
'enabled' => true,
158+
]);
159+
160+
$this->assertEquals((new Status)->current(), SystemStatusEnum::operational);
161+
});

0 commit comments

Comments
 (0)