]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/ShelvesApiTest.php
Tests: Updated comment test to account for new editor usage
[bookstack] / tests / Api / ShelvesApiTest.php
index be276e110040cd156c68e7d996ee26b458a1373c..ba13c0153b14519023a470f005d3bcbb16cf347f 100644 (file)
@@ -4,6 +4,7 @@ namespace Tests\Api;
 
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Bookshelf;
+use BookStack\Entities\Repos\BaseRepo;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\DB;
 use Tests\TestCase;
@@ -28,6 +29,28 @@ class ShelvesApiTest extends TestCase
                 'owned_by' => $firstBookshelf->owned_by,
                 'created_by' => $firstBookshelf->created_by,
                 'updated_by' => $firstBookshelf->updated_by,
+                'cover' => null,
+            ],
+        ]]);
+    }
+
+    public function test_index_endpoint_includes_cover_if_set()
+    {
+        $this->actingAsApiEditor();
+        $shelf = $this->entities->shelf();
+
+        $baseRepo = $this->app->make(BaseRepo::class);
+        $image = $this->files->uploadedImage('shelf_cover');
+        $baseRepo->updateCoverImage($shelf, $image);
+
+        $resp = $this->getJson($this->baseEndpoint . '?filter[id]=' . $shelf->id);
+        $resp->assertJson(['data' => [
+            [
+                'id'   => $shelf->id,
+                'cover' => [
+                    'id' => $shelf->cover->id,
+                    'url' => $shelf->cover->url,
+                ],
             ],
         ]]);
     }