5 use BookStack\Auth\User;
8 class ApiDocsTest extends TestCase
12 protected $endpoint = '/api/docs';
14 public function test_docs_page_not_visible_to_normal_viewers()
16 $viewer = $this->getViewer();
17 $resp = $this->actingAs($viewer)->get($this->endpoint);
18 $resp->assertStatus(403);
20 $resp = $this->actingAsApiEditor()->get($this->endpoint);
21 $resp->assertStatus(200);
24 public function test_docs_page_returns_view_with_docs_content()
26 $resp = $this->actingAsApiEditor()->get($this->endpoint);
27 $resp->assertStatus(200);
28 $resp->assertSee(url('/api/docs.json'));
29 $resp->assertSee('Show a JSON view of the API docs data.');
30 $resp->assertHeader('Content-Type', 'text/html; charset=UTF-8');
33 public function test_docs_json_endpoint_returns_json()
35 $resp = $this->actingAsApiEditor()->get($this->endpoint . '.json');
36 $resp->assertStatus(200);
37 $resp->assertHeader('Content-Type', 'application/json');
40 'name' => 'docs-display',
46 public function test_docs_page_visible_by_public_user_if_given_permission()
48 $this->setSettings(['app-public' => true]);
49 $guest = User::getDefault();
51 $this->startSession();
52 $resp = $this->get('/api/docs');
53 $resp->assertStatus(403);
55 $this->giveUserPermissions($guest, ['access-api']);
57 $resp = $this->get('/api/docs');
58 $resp->assertStatus(200);