diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2022-06-17 07:39:22 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2022-06-17 07:39:22 +0000 |
| commit | bb62df65ac6aa71a757b58a01f9cb95a859a38f9 (patch) | |
| tree | b59576cb558380c7d09847862e796a2fde670fc2 /tests/jsonapi/ConsultationsBookingCreateBySlotIndexTest.php | |
| parent | ad8f5f3b12e4f12bd77f6e2b0f0c3e36c47c5694 (diff) | |
implement tests for consultation jsonapi routes
Closes #1174
Merge request studip/studip!696
Diffstat (limited to 'tests/jsonapi/ConsultationsBookingCreateBySlotIndexTest.php')
| -rw-r--r-- | tests/jsonapi/ConsultationsBookingCreateBySlotIndexTest.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/jsonapi/ConsultationsBookingCreateBySlotIndexTest.php b/tests/jsonapi/ConsultationsBookingCreateBySlotIndexTest.php new file mode 100644 index 0000000..058e5dd --- /dev/null +++ b/tests/jsonapi/ConsultationsBookingCreateBySlotIndexTest.php @@ -0,0 +1,101 @@ +<?php +use JsonApi\Routes\Consultations\BookingsCreate; +use JsonApi\Schemas\ConsultationBooking as Schema; +use JsonAPi\Schemas\User as UserSchema; +use WoohooLabs\Yang\JsonApi\Response\JsonApiResponse; + +require_once __DIR__ . '/ConsultationHelper.php'; + +class ConsultationsBookingCreateBySlotIndexTest 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-slots/{id}/bookings', + BookingsCreate::class, + $credentials, + ['id' => $slot->id], + [ + 'considered_successful' => $considered_succssfull, + 'method' => 'POST', + 'json_body' => [ + 'data' => [ + 'type' => Schema::TYPE, + 'attributes' => [ + 'reason' => self::$BOOKING_DATA['reason'], + ], + 'relationships' => [ + Schema::REL_USER => [ + 'data' => [ + 'type' => UserSchema::TYPE, + 'id' => $user_id, + ], + ] + ] + ] + ] + ] + ); + } +} |
