mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
Added contents to book-show endpoint
Created a generic list formatting helper class for this, to align with logic used on the search results endpoint and for easier future re-use in a standardised way. Also updated some class property types. Added test to cover new books-contents results. Related to #3734
This commit is contained in:
@@ -88,6 +88,38 @@ class BooksApiTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_read_endpoint_includes_chapter_and_page_contents()
|
||||
{
|
||||
$this->actingAsApiEditor();
|
||||
/** @var Book $book */
|
||||
$book = Book::visible()->has('chapters')->has('pages')->first();
|
||||
$chapter = $book->chapters()->first();
|
||||
$chapterPage = $chapter->pages()->first();
|
||||
|
||||
$resp = $this->getJson($this->baseEndpoint . "/{$book->id}");
|
||||
|
||||
$directChildCount = $book->directPages()->count() + $book->chapters()->count();
|
||||
$resp->assertStatus(200);
|
||||
$resp->assertJsonCount($directChildCount, 'contents');
|
||||
$resp->assertJson([
|
||||
'contents' => [
|
||||
[
|
||||
'type' => 'chapter',
|
||||
'id' => $chapter->id,
|
||||
'name' => $chapter->name,
|
||||
'slug' => $chapter->slug,
|
||||
'pages' => [
|
||||
[
|
||||
'id' => $chapterPage->id,
|
||||
'name' => $chapterPage->name,
|
||||
'slug' => $chapterPage->slug,
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint()
|
||||
{
|
||||
$this->actingAsApiEditor();
|
||||
|
||||
Reference in New Issue
Block a user