Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -94,9 +93,9 @@ public function getBookableSlots(
): JsonResponse {
try {
$tz = new DateTimeZone($timeZone);
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->error('Timezone invalid', ['exception' => $e]);
return JsonResponse::fail('Invalid time zone', Http::STATUS_UNPROCESSABLE_ENTITY);
return JsonResponse::fail('Invalid timezone', Http::STATUS_UNPROCESSABLE_ENTITY);
}
// Convert selected date to requesters selected timezone adjusted start and end of day in epoch
$startTimeInTz = (new DateTime($dateSelected, $tz))
Expand Down
7 changes: 3 additions & 4 deletions lib/Service/Appointments/BookingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OCA\Calendar\Exception\ServiceException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\DB\Exception;
use OCP\DB\Exception as DbException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUser;
Expand Down Expand Up @@ -140,8 +139,8 @@ public function book(AppointmentConfig $config, int $start, int $end, string $ti

try {
$tz = new DateTimeZone($timeZone);
} catch (Exception $e) {
throw new InvalidArgumentException('Could not make sense of the timezone', $e->getCode(), $e);
} catch (\Exception $e) {
throw new InvalidArgumentException('Could not make sense of the timezone', previous: $e);
}

$booking = new Booking();
Expand All @@ -156,7 +155,7 @@ public function book(AppointmentConfig $config, int $start, int $end, string $ti
$booking->setTimezone($tz->getName());
try {
$this->bookingMapper->insert($booking);
} catch (Exception $e) {
} catch (DbException $e) {
throw new ServiceException('Could not create booking', 0, $e);
}

Expand Down
11 changes: 8 additions & 3 deletions tests/php/unit/Controller/BookingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use ChristophWurst\Nextcloud\Testing\TestCase;
use DateTime;
use Exception;
use InvalidArgumentException;
use OC\URLGenerator;
use OCA\Calendar\Db\AppointmentConfig;
Expand Down Expand Up @@ -166,9 +165,15 @@ public function testGetBookableSlotsInvalidTimezone(): void {
->with($apptConfg->getToken());
$this->bookingService->expects(self::never())
->method('getAvailableSlots');
$this->expectException(Exception::class);
$this->logger->expects(self::once())
->method('error')
->with('Timezone invalid');

$response = $this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, 'Hook/Neverland');

$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, 'Hook/Neverland');
self::assertInstanceOf(JsonResponse::class, $response);
self::assertSame(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus());
self::assertSame(['status' => 'fail', 'data' => 'Invalid timezone'], $response->getData());
}

public function testGetBookableSlotsTimezoneIdentical(): void {
Expand Down
4 changes: 2 additions & 2 deletions tests/php/unit/Service/Appointments/BookingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use ChristophWurst\Nextcloud\Testing\TestCase;
use DateTimeImmutable;
use Exception;
use InvalidArgumentException;
use OCA\Calendar\Db\AppointmentConfig;
use OCA\Calendar\Db\Booking;
use OCA\Calendar\Db\BookingMapper;
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testBookInvalidTimezone(): void {
$this->random->expects(self::never())
->method('generate');

$this->expectException(Exception::class);
$this->expectExceptionObject(new InvalidArgumentException('Could not make sense of the timezone'));
$this->service->book(new AppointmentConfig(), 4054546654, 44545454, 'Nighttime/DAYTIME!', 'Test', 'test@test.com', 'Test');
}

Expand Down
Loading