]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/ChaptersApiTest.php
Merge branch 'chapter-templates' into development
[bookstack] / tests / Api / ChaptersApiTest.php
index 81a91887794f693acaa5d6df28df9dfca259b716..e2d6cfc81f0a8ce5e12172c7f4c793787feff2e4 100644 (file)
@@ -22,11 +22,12 @@ class ChaptersApiTest extends TestCase
         $resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id');
         $resp->assertJson(['data' => [
             [
-                'id'       => $firstChapter->id,
-                'name'     => $firstChapter->name,
-                'slug'     => $firstChapter->slug,
-                'book_id'  => $firstChapter->book->id,
-                'priority' => $firstChapter->priority,
+                'id'        => $firstChapter->id,
+                'name'      => $firstChapter->name,
+                'slug'      => $firstChapter->slug,
+                'book_id'   => $firstChapter->book->id,
+                'priority'  => $firstChapter->priority,
+                'book_slug' => $firstChapter->book->slug,
             ],
         ]]);
     }
@@ -35,6 +36,7 @@ class ChaptersApiTest extends TestCase
     {
         $this->actingAsApiEditor();
         $book = $this->entities->book();
+        $templatePage = $this->entities->templatePage();
         $details = [
             'name'        => 'My API chapter',
             'description' => 'A chapter created via the API',
@@ -46,6 +48,7 @@ class ChaptersApiTest extends TestCase
                 ],
             ],
             'priority' => 15,
+            'default_template_id' => $templatePage->id,
         ];
 
         $resp = $this->postJson($this->baseEndpoint, $details);
@@ -130,6 +133,7 @@ class ChaptersApiTest extends TestCase
         $resp->assertJson([
             'id'         => $chapter->id,
             'slug'       => $chapter->slug,
+            'book_slug'  => $chapter->book->slug,
             'created_by' => [
                 'name' => $chapter->createdBy->name,
             ],
@@ -147,7 +151,9 @@ class ChaptersApiTest extends TestCase
                     'name' => $page->name,
                 ],
             ],
+            'default_template_id' => null,
         ]);
+        $resp->assertJsonMissingPath('book');
         $resp->assertJsonCount($chapter->pages()->count(), 'pages');
     }
 
@@ -155,6 +161,7 @@ class ChaptersApiTest extends TestCase
     {
         $this->actingAsApiEditor();
         $chapter = $this->entities->chapter();
+        $templatePage = $this->entities->templatePage();
         $details = [
             'name'        => 'My updated API chapter',
             'description' => 'A chapter updated via the API',
@@ -165,6 +172,7 @@ class ChaptersApiTest extends TestCase
                 ],
             ],
             'priority'    => 15,
+            'default_template_id' => $templatePage->id,
         ];
 
         $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);