Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 987a87a1 authored by Christoph Wurst's avatar Christoph Wurst Committed by GitHub
Browse files

Merge pull request #3639 from nextcloud/fix/appointments-no-conflict-cancelled-free

Do not conflict appointments with cancelled or free events
parents e3dc7e64 792d36d4
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -79,9 +79,11 @@ class DailyLimitFilter {
			$events = $this->calendarManger->searchForPrincipal($query);

			$eventsOfSameAppointment = array_filter($events, function(array $event) use ($config) {
				$appointmentToken = $event['objects'][0]['X-NC-APPOINTMENT'][0][0] ?? null;
				$isAppointment = ($event['objects'][0]['X-NC-APPOINTMENT'][0][0] ?? null) === $config->getToken();
				$isCancelled = ($event['objects'][0]['STATUS'][0] ?? null) === 'CANCELLED';
				$isFree = ($event['objects'][0]['TRANSP'][0] ?? null) === 'TRANSPARENT';

				return $config->getToken() === $appointmentToken;
				return $isAppointment && !$isCancelled && !$isFree;
			});

			// Only days with less than the max number are still available
+80 −0
Original line number Diff line number Diff line
@@ -100,6 +100,86 @@ class DailyLimitFilterTest extends TestCase {
		self::assertSame($slots, $filtered);
	}

	public function testOneOtherEventButCancelled(): void {
		$config = new AppointmentConfig();
		$config->setDailyMax(1);
		$config->setUserId('user1');
		$config->setTargetCalendarUri('personal');
		$config->setToken('abc123');
		$slots = [
			new Interval(0, 100),
		];
		$query = $this->createMock(ICalendarQuery::class);
		$this->manager->expects(self::once())
			->method('newQuery')
			->with('principals/users/user1')
			->willReturn($query);
		$this->manager->expects(self::once())
			->method('searchForPrincipal')
			->with($query)
			->willReturn([
				[
					'UID' => 'abc',
					'objects' => [
						0 => [
							'X-NC-APPOINTMENT' => [
								0 => [
									0 => 'abc123',
								],
							],
							'STATUS' => [
								0 => 'CANCELLED',
							],
						],
					],
				]
			]);

		$filtered = $this->filter->filter($config, $slots);

		self::assertSame($slots, $filtered);
	}

	public function testOneOtherEventButFree(): void {
		$config = new AppointmentConfig();
		$config->setDailyMax(1);
		$config->setUserId('user1');
		$config->setTargetCalendarUri('personal');
		$config->setToken('abc123');
		$slots = [
			new Interval(0, 100),
		];
		$query = $this->createMock(ICalendarQuery::class);
		$this->manager->expects(self::once())
			->method('newQuery')
			->with('principals/users/user1')
			->willReturn($query);
		$this->manager->expects(self::once())
			->method('searchForPrincipal')
			->with($query)
			->willReturn([
				[
					'UID' => 'abc',
					'objects' => [
						0 => [
							'X-NC-APPOINTMENT' => [
								0 => [
									0 => 'abc123',
								],
							],
							'STATUS' => [
								0 => 'CANCELLED',
							],
						],
					],
				]
			]);

		$filtered = $this->filter->filter($config, $slots);

		self::assertSame($slots, $filtered);
	}

	public function testOneNotAvailable(): void {
		$config = new AppointmentConfig();
		$config->setDailyMax(1);