diff --git a/tests/integration/api/Controller/ListNotificationsControllerTest.php b/tests/integration/api/Controller/ListNotificationsControllerTest.php deleted file mode 100644 index 8c8bc7ccc..000000000 --- a/tests/integration/api/Controller/ListNotificationsControllerTest.php +++ /dev/null @@ -1,51 +0,0 @@ -prepareDatabase([ - 'users' => [ - $this->normalUser(), - ], - ]); - } - - /** - * @test - */ - public function disallows_index_for_guest() - { - $response = $this->callWith(); - - $this->assertEquals(401, $response->getStatusCode()); - } - - /** - * @test - */ - public function show_index_for_user() - { - $this->actor = User::find(2); - - $response = $this->callWith(); - - $this->assertEquals(200, $response->getStatusCode()); - } -} diff --git a/tests/integration/api/notifications/ListTest.php b/tests/integration/api/notifications/ListTest.php new file mode 100644 index 000000000..1e0b3d2c6 --- /dev/null +++ b/tests/integration/api/notifications/ListTest.php @@ -0,0 +1,57 @@ +prepareDatabase([ + 'users' => [ + $this->normalUser(), + ], + 'access_tokens' => [ + ['token' => 'normaltoken', 'user_id' => 2], + ], + ]); + } + + /** + * @test + */ + public function disallows_index_for_guest() + { + $response = $this->send( + $this->request('GET', '/api/notifications') + ); + + $this->assertEquals(401, $response->getStatusCode()); + } + + /** + * @test + */ + public function shows_index_for_user() + { + $response = $this->send( + $this->request('GET', '/api/notifications') + ->withHeader('Authorization', 'Token normaltoken') + ); + + $this->assertEquals(200, $response->getStatusCode()); + } +} diff --git a/tests/integration/api/Controller/ListUsersControllerTest.php b/tests/integration/api/users/ListTest.php similarity index 60% rename from tests/integration/api/Controller/ListUsersControllerTest.php rename to tests/integration/api/users/ListTest.php index 7747356bf..eac3261fc 100644 --- a/tests/integration/api/Controller/ListUsersControllerTest.php +++ b/tests/integration/api/users/ListTest.php @@ -7,14 +7,15 @@ * LICENSE file that was distributed with this source code. */ -namespace Flarum\Tests\integration\api\Controller; +namespace Flarum\Tests\integration\api\users; -use Flarum\Api\Controller\ListUsersController; +use Flarum\Tests\integration\RetrievesAuthorizedUsers; +use Flarum\Tests\integration\TestCase; use Flarum\User\User; -class ListUsersControllerTest extends ApiControllerTestCase +class ListTest extends TestCase { - protected $controller = ListUsersController::class; + use RetrievesAuthorizedUsers; public function setUp() { @@ -30,6 +31,9 @@ class ListUsersControllerTest extends ApiControllerTestCase 'group_user' => [ ['user_id' => 1, 'group_id' => 1], ], + 'access_tokens' => [ + ['token' => 'admintoken', 'user_id' => 1], + ], ]); } @@ -38,7 +42,9 @@ class ListUsersControllerTest extends ApiControllerTestCase */ public function disallows_index_for_guest() { - $response = $this->callWith(); + $response = $this->send( + $this->request('GET', '/api/users') + ); $this->assertEquals(401, $response->getStatusCode()); } @@ -48,9 +54,10 @@ class ListUsersControllerTest extends ApiControllerTestCase */ public function shows_index_for_admin() { - $this->actor = User::find(1); - - $response = $this->callWith(); + $response = $this->send( + $this->request('GET', '/api/users') + ->withHeader('Authorization', 'Token admintoken') + ); $this->assertEquals(200, $response->getStatusCode()); }