From c9f0673f4b28ae89f726c59be0d6e5ef9a4d4a66 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 3 Apr 2020 14:09:39 +0200 Subject: [PATCH] Add integration test for API root endpoint --- .../tests/integration/api/forum/ShowTest.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 framework/core/tests/integration/api/forum/ShowTest.php diff --git a/framework/core/tests/integration/api/forum/ShowTest.php b/framework/core/tests/integration/api/forum/ShowTest.php new file mode 100644 index 000000000..965473678 --- /dev/null +++ b/framework/core/tests/integration/api/forum/ShowTest.php @@ -0,0 +1,82 @@ +prepareDatabase([ + 'users' => [ + $this->adminUser(), + $this->normalUser(), + ], + 'groups' => [ + $this->adminGroup(), + $this->memberGroup(), + ], + 'group_user' => [ + ['user_id' => 1, 'group_id' => 1], + ['user_id' => 2, 'group_id' => 3], + ], + ]); + } + + /** + * @test + */ + public function normal_user_sees_most_information() + { + $response = $this->send( + $this->request('GET', '/api', [ + 'authenticatedAs' => 2, + ]) + ); + + $this->assertEquals(200, $response->getStatusCode()); + + $json = json_decode($response->getBody()->getContents(), true); + + $this->assertEquals(true, Arr::get($json, 'data.attributes.debug')); + $this->assertEquals('http://localhost', Arr::get($json, 'data.attributes.baseUrl')); + $this->assertEquals('http://localhost/api', Arr::get($json, 'data.attributes.apiUrl')); + + $this->assertArrayNotHasKey('adminUrl', Arr::get($json, 'data.attributes')); + } + + /** + * @test + */ + public function admin_user_sees_even_more() + { + $response = $this->send( + $this->request('GET', '/api', [ + 'authenticatedAs' => 1, + ]) + ); + + $this->assertEquals(200, $response->getStatusCode()); + + $json = json_decode($response->getBody()->getContents(), true); + + $this->assertEquals(true, Arr::get($json, 'data.attributes.debug')); + $this->assertEquals('http://localhost', Arr::get($json, 'data.attributes.baseUrl')); + $this->assertEquals('http://localhost/api', Arr::get($json, 'data.attributes.apiUrl')); + $this->assertEquals('http://localhost/admin', Arr::get($json, 'data.attributes.adminUrl')); + } +}