aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/ConsultationsBookingDeleteTest.php
blob: 2e154debd6a52bc7a873f4d02b7c4cd9f334017f (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
use JsonApi\Routes\Consultations\BookingsDelete;

require_once __DIR__ . '/ConsultationHelper.php';

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

    public function testDeleteBookingWithoutReason(): 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())
        );

        $this->sendMockRequest(
            '/consultation-bookings/{id}',
            BookingsDelete::class,
            $credentials,
            ['id' => $booking->id],
            [
                'considered_successful' => [204],
                'method' => 'DELETE',
            ]
        );
    }

    public function testDeleteBookingWithReason(): 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())
        );

        $this->sendMockRequest(
            '/consultation-bookings/{id}',
            BookingsDelete::class,
            $credentials,
            ['id' => $booking->id],
            [
                'considered_successful' => [204],
                'method' => 'DELETE',
                'json_body' => [
                    'data' => [
                        'attributes' => [
                            'reason' => self::$BOOKING_DATA['reason'],
                        ]
                    ],
                ],
            ]
        );
    }
}