X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/eda9e89c55caf6a98ab57a084d1ce03e0c5fe993..refs/pull/3853/head:/tests/Api/ChaptersApiTest.php diff --git a/tests/Api/ChaptersApiTest.php b/tests/Api/ChaptersApiTest.php index c9ed1a289..d2db0313f 100644 --- a/tests/Api/ChaptersApiTest.php +++ b/tests/Api/ChaptersApiTest.php @@ -2,15 +2,16 @@ 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() { @@ -32,7 +33,7 @@ class ChaptersApiTest extends TestCase public function test_create_endpoint() { $this->actingAsApiEditor(); - $book = Book::query()->first(); + $book = $this->entities->book(); $details = [ 'name' => 'My API chapter', 'description' => 'A chapter created via the API', @@ -62,7 +63,7 @@ class ChaptersApiTest extends TestCase public function test_chapter_name_needed_to_create() { $this->actingAsApiEditor(); - $book = Book::query()->first(); + $book = $this->entities->book(); $details = [ 'book_id' => $book->id, 'description' => 'A chapter created via the API', @@ -93,7 +94,7 @@ class ChaptersApiTest extends TestCase public function test_read_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $page = $chapter->pages()->first(); $resp = $this->getJson($this->baseEndpoint . "/{$chapter->id}"); @@ -125,7 +126,7 @@ class ChaptersApiTest extends TestCase public function test_update_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $details = [ 'name' => 'My updated API chapter', 'description' => 'A chapter created via the API', @@ -147,10 +148,25 @@ class ChaptersApiTest extends TestCase $this->assertActivityExists('chapter_update', $chapter); } + public function test_update_increments_updated_date_if_only_tags_are_sent() + { + $this->actingAsApiEditor(); + $chapter = $this->entities->chapter(); + 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(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->deleteJson($this->baseEndpoint . "/{$chapter->id}"); $resp->assertStatus(204); @@ -160,7 +176,7 @@ class ChaptersApiTest extends TestCase public function test_export_html_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/html"); $resp->assertStatus(200); @@ -171,7 +187,7 @@ class ChaptersApiTest extends TestCase public function test_export_plain_text_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/plaintext"); $resp->assertStatus(200); @@ -182,7 +198,7 @@ class ChaptersApiTest extends TestCase public function test_export_pdf_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/pdf"); $resp->assertStatus(200);