aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ConsultationsBookingShowTest.php
blob: 7295c01708973b3e4ecae42158510a35b5d96a1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use JsonApi\Routes\Consultations\BookingsShow;
use JsonApi\Schemas\ConsultationBooking as Schema;

require_once __DIR__ . '/ConsultationHelper.php';

class ConsultationsBookingShowTest extends Codeception\Test\Unit
{
    use ConsultationHelper;

    public function testFetchBlock(): void
    {
        $credentials = $this->tester->getCredentialsForTestDozent();
        $range = User::find($credentials['id']);

        $block = $this->createBlockWithSlotsForRange($range);
        $slot = $this->getSlotFromBlock($block);
        $booking = $this->createBookingForSlot(
            $credentials,
            $slot,
            $this->getUserForCredentials($this->tester->getCredentialsForTestAutor())
        );

        $response = $this->sendMockRequest(
            '/consultation-bookings/{id}',
            BookingsShow::class,
            $credentials,
            ['id' => $booking->id]
        );
        $document = $this->getSingleResourceDocument($response);

        $resourceObject = $document->primaryResource();
        $this->assertTrue(is_string($resourceObject->id()));
        $this->assertEquals($booking->id, $resourceObject->id());
        $this->assertSame(Schema::TYPE, $resourceObject->type());

        $this->assertEquals(self::$BOOKING_DATA['reason'], $resourceObject->attribute('reason'));

        $this->assertHasRelations($resourceObject, Schema::REL_SLOT, Schema::REL_USER);
    }
}