-
- public function test_all_endpoint_includes_tags_when_requested()
- {
- $this->actingAsApiEditor();
-
- // Create a page and give it a unique name for search
- $page = $this->entities->page();
- $page->name = 'Page With UniqueSearchTerm';
- $page->save();
-
- // Save tags to the page using the existing saveTagsToEntity method
- $tags = [
- ['name' => 'SampleTag', 'value' => 'SampleValue']
- ];
- app(\BookStack\Activity\TagRepo::class)->saveTagsToEntity($page, $tags);
-
- // Ensure the page is indexed for search
- $page->indexForSearch();
-
- // Test without the "tags" include
- $resp = $this->getJson($this->baseEndpoint . '?query=UniqueSearchTerm');
- $resp->assertOk();
- $resp->assertDontSee('tags');
-
- // Test with the "tags" include
- $resp = $this->getJson($this->baseEndpoint . '?query=UniqueSearchTerm&include=tags');
- $resp->assertOk();
-
- // Assert that tags are included in the response
- $resp->assertJsonFragment([
- 'name' => 'SampleTag',
- 'value' => 'SampleValue',
- ]);
-
- // Optionally: check the structure to match the tag order as well
- $resp->assertJsonStructure([
- 'data' => [
- '*' => [
- 'tags' => [
- '*' => [
- 'name',
- 'value',
- 'order',
- ],
- ],
- ],
- ],
- ]);
- }
-
-