]> BookStack Code Mirror - bookstack/commitdiff
Added a few test to cover api docs pages
authorDan Brown <redacted>
Sat, 18 Jan 2020 10:04:13 +0000 (10:04 +0000)
committerDan Brown <redacted>
Sat, 18 Jan 2020 10:04:13 +0000 (10:04 +0000)
tests/Api/ApiDocsTest.php [new file with mode: 0644]
tests/Api/ApiListingTest.php

diff --git a/tests/Api/ApiDocsTest.php b/tests/Api/ApiDocsTest.php
new file mode 100644 (file)
index 0000000..b240c16
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace Tests;
+
+class ApiDocsTest extends TestCase
+{
+    use TestsApi;
+
+    protected $endpoint = '/api/docs';
+
+    public function test_docs_page_not_visible_to_normal_viewers()
+    {
+        $viewer = $this->getViewer();
+        $resp = $this->actingAs($viewer)->get($this->endpoint);
+        $resp->assertStatus(403);
+
+        $resp = $this->actingAsApiEditor()->get($this->endpoint);
+        $resp->assertStatus(200);
+    }
+
+    public function test_docs_page_returns_view_with_docs_content()
+    {
+        $resp = $this->actingAsApiEditor()->get($this->endpoint);
+        $resp->assertStatus(200);
+        $resp->assertSee(url('/api/docs.json'));
+        $resp->assertSee('Show a JSON view of the API docs data.');
+        $resp->assertHeader('Content-Type', 'text/html; charset=UTF-8');
+    }
+
+    public function test_docs_json_endpoint_returns_json()
+    {
+        $resp = $this->actingAsApiEditor()->get($this->endpoint . '.json');
+        $resp->assertStatus(200);
+        $resp->assertHeader('Content-Type', 'application/json');
+        $resp->assertJson([
+            'docs' => [ [
+                'name' => 'docs-display',
+                'uri' => 'api/docs'
+            ] ]
+        ]);
+    }
+}
\ No newline at end of file
index fa28dfb368b79b4141e275dc7875cb87c1240dff..741b9664b9a8dece27895705cf961b9cddc4dc98 100644 (file)
@@ -2,9 +2,7 @@
 
 namespace Tests;
 
-use BookStack\Auth\Permissions\RolePermission;
 use BookStack\Entities\Book;
-use Carbon\Carbon;
 
 class ApiListingTest extends TestCase
 {
Morty Proxy This is a proxified and sanitized view of the page, visit original site.