Skip to content

Commit da2c220

Browse files
committed
Attempted fix to Github CI error - Check if calendar enabled components is empty
1 parent 64c4e98 commit da2c220

4 files changed

Lines changed: 103 additions & 1 deletion

File tree

docs/api/v1/calendars/create.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,17 @@ or
170170
"timestamp": "2026-01-23T15:01:33+01:00"
171171
}
172172
```
173+
174+
**Condition** : If no calendar components are enabled (all of `events_support`, `notes_support`, and `tasks_support` are false).
175+
176+
**Code** : `400 BAD REQUEST`
177+
178+
**Content** :
179+
180+
```json
181+
{
182+
"status": "error",
183+
"message": "At least one calendar component must be enabled (events, notes, or tasks)",
184+
"timestamp": "2026-01-23T15:01:33+01:00"
185+
}
186+
```

docs/api/v1/calendars/edit.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,18 @@ or
164164
"message": "Invalid Calendar Description",
165165
"timestamp": "2026-01-23T15:01:33+01:00"
166166
}
167+
```
168+
169+
**Condition** : If no calendar components are enabled (all of `events_support`, `notes_support`, and `tasks_support` are false).
170+
171+
**Code** : `400 BAD REQUEST`
172+
173+
**Content** :
174+
175+
```json
176+
{
177+
"status": "error",
178+
"message": "At least one calendar component must be enabled (events, notes, or tasks)",
179+
"timestamp": "2026-01-23T15:01:33+01:00"
180+
}
167181
```

src/Controller/Api/ApiController.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,12 @@ public function createNewUserCalendar(Request $request, string $username, Manage
299299
if (true === $tasksSupport || 'true' === $tasksSupport) {
300300
$calendarComponents[] = Calendar::COMPONENT_TODOS;
301301
}
302-
$calendarInstance->getCalendar()->setComponents(implode(',', $calendarComponents));
302+
303+
// Validate that at least one component is selected
304+
if (empty($calendarComponents)) {
305+
return $this->json(['status' => 'error', 'message' => 'At least one calendar component must be enabled (events, notes, or tasks)', 'timestamp' => $this->getTimestamp()], 400);
306+
}
307+
$calendar->setComponents(implode(',', $calendarComponents));
303308

304309
try {
305310
$calendarInstance
@@ -392,6 +397,11 @@ public function editUserCalendar(Request $request, string $username, int $calend
392397
if (true === $tasksSupport || 'true' === $tasksSupport) {
393398
$calendarComponents[] = Calendar::COMPONENT_TODOS;
394399
}
400+
401+
// Validate that at least one component is selected
402+
if (empty($calendarComponents)) {
403+
return $this->json(['status' => 'error', 'message' => 'At least one calendar component must be enabled (events, notes, or tasks)', 'timestamp' => $this->getTimestamp()], 400);
404+
}
395405
$calendarInstance->getCalendar()->setComponents(implode(',', $calendarComponents));
396406

397407
try {

tests/Functional/ApiControllerTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,68 @@ public function testUnshareUserCalendar(): void
441441
$this->assertArrayHasKey('data', $data);
442442
$this->assertEmpty($data['data']);
443443
}
444+
445+
/*
446+
* Test creating a calendar with no components enabled should return validation error
447+
*/
448+
public function testCreateUserCalendarNoComponents(): void
449+
{
450+
$client = static::createClient();
451+
$username = $this->getUserUsername($client, 0);
452+
453+
// Create calendar API request with no components enabled
454+
$payload = [
455+
'uri' => 'no_components_calendar',
456+
'name' => 'no.components.calendar',
457+
'description' => 'no.components.description',
458+
'events_support' => false,
459+
'tasks_support' => false,
460+
'notes_support' => false,
461+
];
462+
463+
$client->request('POST', '/api/v1/calendars/'.$username.'/create', [], [], [
464+
'HTTP_ACCEPT' => 'application/json',
465+
'HTTP_X_DAVIS_API_TOKEN' => $_ENV['API_KEY'],
466+
'CONTENT_TYPE' => 'application/json',
467+
], json_encode($payload));
468+
469+
$this->assertResponseStatusCodeSame(400);
470+
$this->assertResponseHeaderSame('Content-Type', 'application/json');
471+
472+
$data = json_decode($client->getResponse()->getContent(), true);
473+
$this->assertEquals('error', $data['status']);
474+
$this->assertStringContainsString('At least one calendar component must be enabled', $data['message']);
475+
}
476+
477+
/*
478+
* Test editing a calendar with no components enabled should return validation error
479+
*/
480+
public function testEditUserCalendarNoComponents(): void
481+
{
482+
$client = static::createClient();
483+
$username = $this->getUserUsername($client, 0);
484+
$calendarId = $this->getCalendarId($client, $username, true);
485+
486+
// Edit calendar API request with no components enabled
487+
$payload = [
488+
'name' => 'edited.calendar.title',
489+
'description' => 'edited.calendar.description',
490+
'events_support' => false,
491+
'tasks_support' => false,
492+
'notes_support' => false,
493+
];
494+
495+
$client->request('POST', '/api/v1/calendars/'.$username.'/'.$calendarId.'/edit', [], [], [
496+
'HTTP_ACCEPT' => 'application/json',
497+
'HTTP_X_DAVIS_API_TOKEN' => $_ENV['API_KEY'],
498+
'CONTENT_TYPE' => 'application/json',
499+
], json_encode($payload));
500+
501+
$this->assertResponseStatusCodeSame(400);
502+
$this->assertResponseHeaderSame('Content-Type', 'application/json');
503+
504+
$data = json_decode($client->getResponse()->getContent(), true);
505+
$this->assertEquals('error', $data['status']);
506+
$this->assertStringContainsString('At least one calendar component must be enabled', $data['message']);
507+
}
444508
}

0 commit comments

Comments
 (0)