+ public function test_update_endpoint_with_html()
+ {
+ $this->actingAsApiEditor();
+ $chapter = $this->entities->chapter();
+ $details = [
+ 'name' => 'My updated API chapter',
+ 'description_html' => '<p>A chapter <em>updated</em> via the API</p>',
+ ];
+
+ $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);
+ $resp->assertStatus(200);
+
+ $this->assertDatabaseHas('chapters', array_merge($details, [
+ 'id' => $chapter->id, 'description' => 'A chapter updated via the API'
+ ]));
+ }
+
+ 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_update_with_book_id_moves_chapter()
+ {
+ $this->actingAsApiEditor();
+ $chapter = $this->entities->chapterHasPages();
+ $page = $chapter->pages()->first();
+ $newBook = Book::query()->where('id', '!=', $chapter->book_id)->first();
+
+ $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", ['book_id' => $newBook->id]);
+ $resp->assertOk();
+ $chapter->refresh();
+
+ $this->assertDatabaseHas('chapters', ['id' => $chapter->id, 'book_id' => $newBook->id]);
+ $this->assertDatabaseHas('pages', ['id' => $page->id, 'book_id' => $newBook->id, 'chapter_id' => $chapter->id]);
+ }
+
+ public function test_update_with_new_book_id_requires_delete_permission()
+ {
+ $editor = $this->users->editor();
+ $this->permissions->removeUserRolePermissions($editor, ['chapter-delete-all', 'chapter-delete-own']);
+ $this->actingAs($editor);
+ $chapter = $this->entities->chapterHasPages();
+ $newBook = Book::query()->where('id', '!=', $chapter->book_id)->first();
+
+ $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", ['book_id' => $newBook->id]);
+ $this->assertPermissionError($resp);
+ }
+