]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/ChaptersApiTest.php
Added 'Sort Book' action to chapters
[bookstack] / tests / Api / ChaptersApiTest.php
index c9ed1a2892e19a715dd344e4a4ac8e6b5302b41a..8d31500ebc19ce3360cddfd7d823eab03fe4cab4 100644 (file)
@@ -4,13 +4,15 @@ namespace Tests\Api;
 
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Chapter;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
 use Tests\TestCase;
 
 class ChaptersApiTest extends TestCase
 {
     use TestsApi;
 
-    protected $baseEndpoint = '/api/chapters';
+    protected string $baseEndpoint = '/api/chapters';
 
     public function test_index_endpoint_returns_expected_chapter()
     {
@@ -147,6 +149,21 @@ class ChaptersApiTest extends TestCase
         $this->assertActivityExists('chapter_update', $chapter);
     }
 
+    public function test_update_increments_updated_date_if_only_tags_are_sent()
+    {
+        $this->actingAsApiEditor();
+        $chapter = Chapter::visible()->first();
+        DB::table('chapters')->where('id', '=', $chapter->id)->update(['updated_at' => Carbon::now()->subWeek()]);
+
+        $details = [
+            'tags' => [['name' => 'Category', 'value' => 'Testing']],
+        ];
+
+        $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
+        $chapter->refresh();
+        $this->assertGreaterThan(Carbon::now()->subDay()->unix(), $chapter->updated_at->unix());
+    }
+
     public function test_delete_endpoint()
     {
         $this->actingAsApiEditor();