Closed swayok closed 11 months ago
Thanks @swayok. This is nice to solve this problem, and I appreciate your effort. Could we write a test to see when the problem happened and what we solved exactly in this PR?
@hkulekci added test case for RangeQuery but I wasn't able to run it.
@matchish could you approve to be able to see test results?
@hkulekci added test case for RangeQuery but I wasn't able to run it.
Hey @swayok thanks for the quick response and the tests. Let's wait for @matchish. I hope he will approve soon.
All modified lines are covered by tests :white_check_mark:
Comparison is base (
97e5578
) 96.06% compared to head (ac3b9ff
) 96.08%.
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
LGTM. I prefer splitting the tests into different functions. But at least for now, it shows that the implementation is working. If you can, please could you move the test into a new test function as below :
public function test_search_with_custom_filter()
{
$dispatcher = Product::getEventDispatcher();
Product::unsetEventDispatcher();
$kindleCheapAmount = rand(1, 5);
$iphoneLuxuryAmount = rand(1, 5);
$iphonePromoUsedAmount = rand(1, 5);
$iphonePromoNewAmount = rand(6, 10);
$iphonePromoLikeNewAmount = rand(1, 5);
$iphonePromoUsedAndLikeNewAmount = $iphonePromoLikeNewAmount + $iphonePromoUsedAmount;
factory(Product::class, $kindleCheapAmount)->states(['iphone', 'cheap'])->create();
factory(Product::class, $iphoneLuxuryAmount)->states(['iphone', 'luxury'])->create();
factory(Product::class, $iphonePromoUsedAmount)->states(['iphone', 'promo', 'used'])->create();
factory(Product::class, $iphonePromoNewAmount)->states(['iphone', 'promo', 'new'])->create();
factory(Product::class, $iphonePromoLikeNewAmount)->states(['iphone', 'promo', 'like new'])->create();
Product::setEventDispatcher($dispatcher);
Artisan::call('scout:import');
// Promo Product Test
$iphonePromoUsedAndLikeNewWithRange = Product::search('iphone')
->where('price', new RangeQuery('price', [
RangeQuery::GTE => 100, // Promo Products
RangeQuery::LTE => 100, // Promo Products
]))
->whereIn('type', ['used', 'like new'])
->get();
$this->assertEquals($iphonePromoUsedAndLikeNewWithRange->count(), $iphonePromoUsedAndLikeNewAmount);
$this->assertInstanceOf(Product::class, $iphonePromoUsedAndLikeNewWithRange->first(), 'Promo Product Assert');
// Luxury Product Test
$iphoneLuxuryUsedAndLikeNewWithRange = Product::search('iphone')
->where('price', new RangeQuery('price', [
RangeQuery::GTE => 1000, // Luxury Products
]))
->get();
$this->assertEquals($iphoneLuxuryUsedAndLikeNewWithRange->count(), $iphoneLuxuryAmount, 'Luxury Product Count Assert');
$this->assertInstanceOf(Product::class, $iphoneLuxuryUsedAndLikeNewWithRange->first());
// Cheap Product Test
$iphoneCheapWithRange = Product::search('iphone')
->where('price', new RangeQuery('price', [
RangeQuery::LTE => 70, // Cheap Products
]))
->get();
$this->assertEquals($kindleCheapAmount, $iphoneCheapWithRange->count(), 'Cheap Product Count Assert');
$this->assertInstanceOf(Product::class, $iphoneCheapWithRange->first());
}
Thanks @swayok. ^_^
And could you update README plz?
Done
Hey, @swayok, thanks for the quick update. I appreciate it.
@matchish LGTM!
Released! Thanks @swayok. Really nice feature
For https://github.com/matchish/laravel-scout-elasticsearch/issues/259