]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/ChaptersApiTest.php
added template to chapter API controller
[bookstack] / tests / Api / ChaptersApiTest.php
index a99a85af8167b9009e01718ea086b5b92408102d..81a91887794f693acaa5d6df28df9dfca259b716 100644 (file)
@@ -45,12 +45,17 @@ class ChaptersApiTest extends TestCase
                     'value' => 'tagvalue',
                 ],
             ],
+            'priority' => 15,
         ];
 
         $resp = $this->postJson($this->baseEndpoint, $details);
         $resp->assertStatus(200);
         $newItem = Chapter::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
-        $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
+        $resp->assertJson(array_merge($details, [
+            'id' => $newItem->id,
+            'slug' => $newItem->slug,
+            'description_html' => '<p>A chapter created via the API</p>',
+        ]));
         $this->assertDatabaseHas('tags', [
             'entity_id'   => $newItem->id,
             'entity_type' => $newItem->getMorphClass(),
@@ -61,35 +66,26 @@ class ChaptersApiTest extends TestCase
         $this->assertActivityExists('chapter_create', $newItem);
     }
 
-    public function test_create_applies_correct_priority()
+    public function test_create_endpoint_with_html()
     {
         $this->actingAsApiEditor();
         $book = $this->entities->book();
         $details = [
-            'name'        => 'My API chapter',
-            'description' => 'A chapter created via the API',
-            'book_id'     => $book->id,
-            'tags'        => [
-                [
-                    'name'  => 'tagname',
-                    'value' => 'tagvalue',
-                ],
-            ],
-            'priority'     => 15,
+            'name'             => 'My API chapter',
+            'description_html' => '<p>A chapter <strong>created</strong> via the API</p>',
+            'book_id'          => $book->id,
         ];
 
         $resp = $this->postJson($this->baseEndpoint, $details);
         $resp->assertStatus(200);
         $newItem = Chapter::query()->orderByDesc('id')->where('name', '=', $details['name'])->first();
-        $resp->assertJson(array_merge($details, ['id' => $newItem->id, 'slug' => $newItem->slug]));
-        $this->assertDatabaseHas('tags', [
-            'entity_id'   => $newItem->id,
-            'entity_type' => $newItem->getMorphClass(),
-            'name'        => 'tagname',
-            'value'       => 'tagvalue',
+
+        $expectedDetails = array_merge($details, [
+            'id'          => $newItem->id,
+            'description' => 'A chapter created via the API',
         ]);
-        $resp->assertJsonMissing(['pages' => []]);
-        $this->assertActivityExists('chapter_create', $newItem);
+        $resp->assertJson($expectedDetails);
+        $this->assertDatabaseHas('chapters', $expectedDetails);
     }
 
     public function test_chapter_name_needed_to_create()
@@ -161,7 +157,7 @@ class ChaptersApiTest extends TestCase
         $chapter = $this->entities->chapter();
         $details = [
             'name'        => 'My updated API chapter',
-            'description' => 'A chapter created via the API',
+            'description' => 'A chapter updated via the API',
             'tags'        => [
                 [
                     'name'  => 'freshtag',
@@ -176,11 +172,31 @@ class ChaptersApiTest extends TestCase
 
         $resp->assertStatus(200);
         $resp->assertJson(array_merge($details, [
-            'id' => $chapter->id, 'slug' => $chapter->slug, 'book_id' => $chapter->book_id,
+            'id' => $chapter->id,
+            'slug' => $chapter->slug,
+            'book_id' => $chapter->book_id,
+            'description_html' => '<p>A chapter updated via the API</p>',
         ]));
         $this->assertActivityExists('chapter_update', $chapter);
     }
 
+    public function test_update_endpoint_with_html()
+    {
+        $this->actingAsApiEditor();
+        $chapter = $this->entities->chapter();
+        $details = [
+            'name'             => 'My updated API chapter',
+            'description_html' => '<p>A chapter <em>updated</em> via the API</p>',
+        ];
+
+        $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
+        $resp->assertStatus(200);
+
+        $this->assertDatabaseHas('chapters', array_merge($details, [
+            'id' => $chapter->id, 'description' => 'A chapter updated via the API'
+        ]));
+    }
+
     public function test_update_increments_updated_date_if_only_tags_are_sent()
     {
         $this->actingAsApiEditor();