GetCurrentUserApiTest.php 925 Bytes
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
<?php


namespace Tests\Feature\Api\Me;

Jacob Priddy's avatar
Jacob Priddy committed
6
use Illuminate\Testing\TestResponse;
Jacob Priddy's avatar
Jacob Priddy committed
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
use Tests\Feature\AuthenticatesWithApplicationTestCase;

class GetCurrentUserApiTest extends AuthenticatesWithApplicationTestCase
{
    protected TestResponse $response;

    protected function handleTest(): void
    {
        $this->response = $this->getJson('/me?api_token=' . $this->authToken);
    }

    /**
     * @test
     */
    public function it_requires_a_logged_in_user(): void
    {
        $this->handleTest();

        $this->response->assertStatus(401);
    }

    /**
     * @test
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function it_gets_the_logged_in_user(): void
    {
        $this->authenticate();

        $this->handleTest();

        $this->response->assertStatus(200);
        $this->response->assertJson(['user' => [
            'id' => $this->authUser->getId()
        ]]);
    }
}