]> BookStack Code Mirror - bookstack/blob - tests/Api/UsersApiTest.php
Refactored existing user API work
[bookstack] / tests / Api / UsersApiTest.php
1 <?php
2
3 namespace Tests\Api;
4
5 use BookStack\Auth\Role;
6 use BookStack\Auth\User;
7 use Tests\TestCase;
8
9 class UsersApiTest extends TestCase
10 {
11     use TestsApi;
12
13     protected $baseEndpoint = '/api/users';
14
15     public function test_users_manage_permission_needed_for_all_endpoints()
16     {
17         // TODO
18     }
19
20     public function test_index_endpoint_returns_expected_shelf()
21     {
22         $this->actingAsApiAdmin();
23         /** @var User $firstUser */
24         $firstUser = User::query()->orderBy('id', 'asc')->first();
25
26         $resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id');
27         $resp->assertJson(['data' => [
28             [
29                 'id'   => $firstUser->id,
30                 'name' => $firstUser->name,
31                 'slug' => $firstUser->slug,
32                 'email' => $firstUser->email,
33                 'profile_url' => $firstUser->getProfileUrl(),
34                 'edit_url' => $firstUser->getEditUrl(),
35                 'avatar_url' => $firstUser->getAvatar(),
36             ],
37         ]]);
38     }
39
40     public function test_read_endpoint()
41     {
42         $this->actingAsApiAdmin();
43         /** @var User $user */
44         $user = User::query()->first();
45         /** @var Role $userRole */
46         $userRole = $user->roles()->first();
47
48         $resp = $this->getJson($this->baseEndpoint . "/{$user->id}");
49
50         $resp->assertStatus(200);
51         $resp->assertJson([
52             'id'         => $user->id,
53             'slug'       => $user->slug,
54             'email'      => $user->email,
55             'external_auth_id' => $user->external_auth_id,
56             'roles' => [
57                 [
58                     'id' => $userRole->id,
59                     'display_name' => $userRole->display_name,
60                 ]
61             ],
62         ]);
63     }
64 }