X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c429cf78187e80deb63982a282a1c6889f30291a..refs/pull/3593/head:/tests/Api/ChaptersApiTest.php diff --git a/tests/Api/ChaptersApiTest.php b/tests/Api/ChaptersApiTest.php index b3dd0ae6b..8d31500eb 100644 --- a/tests/Api/ChaptersApiTest.php +++ b/tests/Api/ChaptersApiTest.php @@ -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(); @@ -200,4 +217,17 @@ class ChaptersApiTest extends TestCase $resp->assertSee('# ' . $chapter->name); $resp->assertSee('# ' . $chapter->pages()->first()->name); } + + public function test_cant_export_when_not_have_permission() + { + $types = ['html', 'plaintext', 'pdf', 'markdown']; + $this->actingAsApiEditor(); + $this->removePermissionFromUser($this->getEditor(), 'content-export'); + + $chapter = Chapter::visible()->has('pages')->first(); + foreach ($types as $type) { + $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/{$type}"); + $this->assertPermissionError($resp); + } + } }