Skip to content

Commit

Permalink
Chapters API: Added missing book_slug field
Browse files Browse the repository at this point in the history
Was removed during previous changes, but reflected in response examples.
This adds into all standard single chapter responses.
For #4765
  • Loading branch information
ssddanbrown committed Jan 16, 2024
1 parent afbbcaf commit adf1806
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/Entities/Controllers/ChapterApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ protected function forJsonDisplay(Chapter $chapter): Chapter
$chapter->unsetRelations()->refresh();

$chapter->load(['tags']);
$chapter->makeVisible('description_html')
->setAttribute('description_html', $chapter->descriptionHtml());
$chapter->makeVisible('description_html');
$chapter->setAttribute('description_html', $chapter->descriptionHtml());
$chapter->setAttribute('book_slug', $chapter->book()->first()->slug);

return $chapter;
}
Expand Down
1 change: 1 addition & 0 deletions dev/api/responses/chapters-create.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"updated_by": 1,
"owned_by": 1,
"description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>",
"book_slug": "example-book",
"tags": [
{
"name": "Category",
Expand Down
1 change: 1 addition & 0 deletions dev/api/responses/chapters-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"updated_by": 1,
"owned_by": 1,
"description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
"book_slug": "example-book",
"tags": [
{
"name": "Category",
Expand Down
13 changes: 8 additions & 5 deletions tests/Api/ChaptersApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public function test_index_endpoint_returns_expected_chapter()
$resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id');
$resp->assertJson(['data' => [
[
'id' => $firstChapter->id,
'name' => $firstChapter->name,
'slug' => $firstChapter->slug,
'book_id' => $firstChapter->book->id,
'priority' => $firstChapter->priority,
'id' => $firstChapter->id,
'name' => $firstChapter->name,
'slug' => $firstChapter->slug,
'book_id' => $firstChapter->book->id,
'priority' => $firstChapter->priority,
'book_slug' => $firstChapter->book->slug,
],
]]);
}
Expand Down Expand Up @@ -130,6 +131,7 @@ public function test_read_endpoint()
$resp->assertJson([
'id' => $chapter->id,
'slug' => $chapter->slug,
'book_slug' => $chapter->book->slug,
'created_by' => [
'name' => $chapter->createdBy->name,
],
Expand All @@ -148,6 +150,7 @@ public function test_read_endpoint()
],
],
]);
$resp->assertJsonMissingPath('book');
$resp->assertJsonCount($chapter->pages()->count(), 'pages');
}

Expand Down

0 comments on commit adf1806

Please sign in to comment.