Skip to content

Commit

Permalink
Fix product filter and sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Witold Wiśniewski committed Sep 25, 2023
1 parent f59921a commit b3eed68
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Criteria/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class ProductSearch extends Criterion
public function query(Builder $query): Builder
{
return $query->whereFullText([
'name',
'description_html',
'description_short',
'search_values',
'products.name',
'products.description_html',
'products.description_short',
'products.search_values',
], $this->value);
}
}
28 changes: 28 additions & 0 deletions tests/Feature/ProductSearchDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ public function testIndexIdsSearch($user): void
->assertJsonCount(2, 'data');
}

/**
* @dataProvider authProvider
*/
public function testIndexSearch($user): void
{
$this->{$user}->givePermissionTo('products.show');

Product::factory()->create([
'public' => true,
'name' => 'First',
]);

Product::factory()->create([
'public' => true,
'created_at' => Carbon::now()->addHour(),
'name' => 'Second',
]);

// This test check if there is no SQL error that 'name' is ambiguous
$this
->actingAs($this->{$user})
->json('GET', '/products', [
'search' => 'First',
'sort' => 'attribute.data-wydania:desc',
])
->assertOk();
}

/**
* @dataProvider authProvider
*/
Expand Down

0 comments on commit b3eed68

Please sign in to comment.