Skip to content

Commit

Permalink
- Remove usage of Algolia\SearchIndex in the novapackages API.
Browse files Browse the repository at this point in the history
- Use the collection scout driver for testing.
- Enable the search API test class which was previously marked incomplete.
  • Loading branch information
omarrida committed Oct 5, 2024
1 parent 7411140 commit cb8dc13
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 14 deletions.
4 changes: 1 addition & 3 deletions app/Http/Controllers/Api/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function __invoke(Request $request)
private function searchFor($q)
{
return Cache::remember(CacheKeys::packageSearchResults($q), self::CACHE_LENGTH, function () use ($q) {
return Package::search($q, function (SearchIndex $algolia, string $query, array $options) {
return $algolia->search($query, array_merge($options, ['advancedSyntax' => true]));
})->get()->load(['tags', 'author']);
return Package::search($q)->get()->load(['tags', 'author']);
});
}
}
1 change: 0 additions & 1 deletion app/Http/Livewire/PackageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Livewire;

use Algolia\AlgoliaSearch\SearchIndex;
use App\CacheKeys;
use App\Package;
use App\Tag;
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
<env name="SCOUT_DRIVER" value="null"/>
<env name="SCOUT_DRIVER" value="collection"/>
</php>
</phpunit>
7 changes: 0 additions & 7 deletions tests/Feature/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ class SearchTest extends TestCase
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

$this->markTestIncomplete('Need to figure out how to test with Scout.');
}

/** @test */
public function it_returns_matching_results(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public function it_excludes_attributes_from_being_synchronized_to_the_scout_sear
}

/** @test */
public function the_readme_is_truncated_to_500_characters_when_being_synchronized_with_the_scout_index(): void
public function the_readme_is_preserved_even_when_its_above_500_characters_when_being_synchronized_with_the_scout_index(): void
{
$package = Package::factory()->create([
'readme' => Str::random(1400),
]);

$searchableArray = $package->toSearchableArray();

$this->assertEquals(500, strlen($searchableArray['readme']));
$this->assertEquals(1400, strlen($searchableArray['readme']));
}

/**
Expand Down

0 comments on commit cb8dc13

Please sign in to comment.