+ 'total' => 2,
+ ]);
+ }
+
+ public function test_index_endpoint_returns_children()
+ {
+ $this->actingAsAuthorizedUser();
+
+ $book = Book::query()->whereHas('pages')->whereHas('chapters')->withCount(['pages', 'chapters'])->first();
+ $editor = $this->getEditor();
+ $this->actingAs($editor)->delete($book->getUrl());
+
+ $deletion = Deletion::query()->orderBy('id')->first();
+
+ $resp = $this->getJson($this->baseEndpoint);
+
+ $expectedData = [
+ [
+ 'id' => $deletion->getKey(),
+ 'deleted_by' => $editor->getKey(),
+ 'created_at' => $deletion->created_at->toJson(),
+ 'updated_at' => $deletion->updated_at->toJson(),
+ 'deletable_type' => $book->getMorphClass(),
+ 'deletable_id' => $book->getKey(),
+ 'children' => [
+ 'Bookstack\Page' => $book->pages_count,
+ 'Bookstack\Chapter' => $book->chapters_count,
+ ],
+ 'parent' => null,
+ ]
+ ];
+
+ $resp->assertJson([
+ 'data' => $expectedData,
+ 'total' => 1,
+ ]);
+ }
+
+ public function test_index_endpoint_returns_parent()
+ {
+ $this->actingAsAuthorizedUser();
+
+ $page = Page::query()->whereHas('chapter')->with('chapter')->first();
+
+ $editor = $this->getEditor();
+ $this->actingAs($editor)->delete($page->getUrl());
+
+ $deletion = Deletion::query()->orderBy('id')->first();
+
+ $resp = $this->getJson($this->baseEndpoint);
+
+ $expectedData = [
+ [
+ 'id' => $deletion->getKey(),
+ 'deleted_by' => $editor->getKey(),
+ 'created_at' => $deletion->created_at->toJson(),
+ 'updated_at' => $deletion->updated_at->toJson(),
+ 'deletable_type' => $page->getMorphClass(),
+ 'deletable_id' => $page->getKey(),
+ 'parent' => [
+ 'type' => 'BookStack\Chapter',
+ 'id' => $page->chapter->getKey()
+ ],
+ 'children' => null,
+ ]
+ ];
+
+ $resp->assertJson([
+ 'data' => $expectedData,
+ 'total' => 1