aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ConsultationsBookingCreateTest.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2022-06-17 07:39:22 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2022-06-17 07:39:22 +0000
commitbb62df65ac6aa71a757b58a01f9cb95a859a38f9 (patch)
treeb59576cb558380c7d09847862e796a2fde670fc2 /tests/jsonapi/ConsultationsBookingCreateTest.php
parentad8f5f3b12e4f12bd77f6e2b0f0c3e36c47c5694 (diff)
implement tests for consultation jsonapi routes
Closes #1174 Merge request studip/studip!696
Diffstat (limited to 'tests/jsonapi/ConsultationsBookingCreateTest.php')
-rw-r--r--tests/jsonapi/ConsultationsBookingCreateTest.php108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/jsonapi/ConsultationsBookingCreateTest.php b/tests/jsonapi/ConsultationsBookingCreateTest.php
new file mode 100644
index 0000000..493bf97
--- /dev/null
+++ b/tests/jsonapi/ConsultationsBookingCreateTest.php
@@ -0,0 +1,108 @@
+<?php
+use JsonApi\Routes\Consultations\BookingsCreate;
+use JsonApi\Schemas\ConsultationBooking as Schema;
+use JsonAPi\Schemas\User as UserSchema;
+use JsonAPi\Schemas\ConsultationSlot as SlotSchema;
+use WoohooLabs\Yang\JsonApi\Response\JsonApiResponse;
+
+require_once __DIR__ . '/ConsultationHelper.php';
+
+class ConsultationsBookingCreateTest extends Codeception\Test\Unit
+{
+ use ConsultationHelper;
+
+ public function testAutorMayCreateBooking(): void
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $range = User::find($credentials['id']);
+
+ $block = $this->createBlockWithSlotsForRange($range);
+ $slot = $this->getSlotFromBlock($block);
+
+ $this->createBooking(
+ $credentials,
+ $slot,
+ $this->tester->getCredentialsForTestAutor()['id'],
+ [201]
+ );
+ }
+
+ public function testSlotIsOccupied(): void
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $range = User::find($credentials['id']);
+
+ $block = $this->createBlockWithSlotsForRange($range);
+ $slot = $this->getSlotFromBlock($block);
+
+ $this->createBooking(
+ $credentials,
+ $slot,
+ $this->tester->getCredentialsForTestAutor()['id'],
+ [201]
+ );
+
+ $response = $this->createBooking(
+ $credentials,
+ $slot,
+ $this->tester->getCredentialsForTestAutor()['id'],
+ null
+ );
+
+ $this->assertEquals(409, $response->getStatusCode());
+ }
+
+ public function testRootMayNotCreateBooking(): void
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $range = User::find($credentials['id']);
+
+ $block = $this->createBlockWithSlotsForRange($range);
+ $slot = $this->getSlotFromBlock($block);
+
+ $response = $this->createBooking(
+ $credentials,
+ $slot,
+ $this->tester->getCredentialsForRoot()['id'],
+ null
+ );
+
+ $this->assertEquals(403, $response->getStatusCode());
+ }
+
+ private function createBooking(array $credentials, ConsultationSlot $slot, string $user_id, ?array $considered_succssfull): JsonApiResponse
+ {
+ return $this->sendMockRequest(
+ '/consultation-bookings',
+ BookingsCreate::class,
+ $credentials,
+ [],
+ [
+ 'considered_successful' => $considered_succssfull,
+ 'method' => 'POST',
+ 'json_body' => [
+ 'data' => [
+ 'type' => Schema::TYPE,
+ 'attributes' => [
+ 'reason' => self::$BOOKING_DATA['reason'],
+ ],
+ 'relationships' => [
+ Schema::REL_SLOT => [
+ 'data' => [
+ 'type' => SlotSchema::TYPE,
+ 'id' => $slot->id,
+ ],
+ ],
+ Schema::REL_USER => [
+ 'data' => [
+ 'type' => UserSchema::TYPE,
+ 'id' => $user_id,
+ ],
+ ],
+ ]
+ ]
+ ]
+ ]
+ );
+ }
+}