]> BookStack Code Mirror - bookstack/blob - tests/Api/ApiDocsTest.php
Added a few test to cover api docs pages
[bookstack] / tests / Api / ApiDocsTest.php
1 <?php
2
3 namespace Tests;
4
5 class ApiDocsTest extends TestCase
6 {
7     use TestsApi;
8
9     protected $endpoint = '/api/docs';
10
11     public function test_docs_page_not_visible_to_normal_viewers()
12     {
13         $viewer = $this->getViewer();
14         $resp = $this->actingAs($viewer)->get($this->endpoint);
15         $resp->assertStatus(403);
16
17         $resp = $this->actingAsApiEditor()->get($this->endpoint);
18         $resp->assertStatus(200);
19     }
20
21     public function test_docs_page_returns_view_with_docs_content()
22     {
23         $resp = $this->actingAsApiEditor()->get($this->endpoint);
24         $resp->assertStatus(200);
25         $resp->assertSee(url('/api/docs.json'));
26         $resp->assertSee('Show a JSON view of the API docs data.');
27         $resp->assertHeader('Content-Type', 'text/html; charset=UTF-8');
28     }
29
30     public function test_docs_json_endpoint_returns_json()
31     {
32         $resp = $this->actingAsApiEditor()->get($this->endpoint . '.json');
33         $resp->assertStatus(200);
34         $resp->assertHeader('Content-Type', 'application/json');
35         $resp->assertJson([
36             'docs' => [ [
37                 'name' => 'docs-display',
38                 'uri' => 'api/docs'
39             ] ]
40         ]);
41     }
42 }