actingAsApiEditor();
$uniqueTerm = 'MySuperUniqueTermForSearching';
/** @var Entity $entityClass */
foreach ([Page::class, Chapter::class, Book::class, Bookshelf::class] as $entityClass) {
/** @var Entity $first */
$first = $entityClass::query()->first();
$first->update(['name' => $uniqueTerm]);
$first->indexForSearch();
}
$resp = $this->getJson($this->baseEndpoint . '?query=' . $uniqueTerm . '&count=5&page=1');
$resp->assertJsonCount(4, 'data');
$resp->assertJsonFragment(['name' => $uniqueTerm, 'type' => 'book']);
$resp->assertJsonFragment(['name' => $uniqueTerm, 'type' => 'chapter']);
$resp->assertJsonFragment(['name' => $uniqueTerm, 'type' => 'page']);
$resp->assertJsonFragment(['name' => $uniqueTerm, 'type' => 'bookshelf']);
}
public function test_all_endpoint_returns_entity_url()
{
$page = $this->entities->page();
$page->update(['name' => 'name with superuniquevalue within']);
$page->indexForSearch();
$resp = $this->actingAsApiAdmin()->getJson($this->baseEndpoint . '?query=superuniquevalue');
$resp->assertJsonFragment([
'type' => 'page',
'url' => $page->getUrl(),
]);
}
public function test_all_endpoint_returns_items_with_preview_html()
{
$book = $this->entities->book();
$book->forceFill(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within'])->save();
$book->indexForSearch();
$resp = $this->actingAsApiAdmin()->getJson($this->baseEndpoint . '?query=superuniquevalue');
$resp->assertJsonFragment([
'type' => 'book',
'url' => $book->getUrl(),
'preview_html' => [
'name' => 'name with superuniquevalue within',
'content' => 'Description with superuniquevalue within',
],
]);
}
public function test_all_endpoint_requires_query_parameter()
{
$resp = $this->actingAsApiEditor()->get($this->baseEndpoint);
$resp->assertStatus(422);
$resp = $this->actingAsApiEditor()->get($this->baseEndpoint . '?query=myqueryvalue');
$resp->assertOk();
}
}