Skip to content

Commit

Permalink
Test no import unsearchable models
Browse files Browse the repository at this point in the history
  • Loading branch information
matchish committed Oct 6, 2019
1 parent 5f4d06f commit 258f310
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/Feature/ImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function test_import_entites(): void

factory(Product::class, $productsAmount)->create();

$productsUnsearchableAmount = rand(1, 5);
factory(Product::class, $productsUnsearchableAmount)->states(['archive'])->create();

Product::setEventDispatcher($dispatcher);

Artisan::call('scout:import', [
Expand All @@ -47,7 +50,6 @@ public function test_import_entites_in_queue(): void
Product::unsetEventDispatcher();

$productsAmount = rand(1, 5);

factory(Product::class, $productsAmount)->create();

Product::setEventDispatcher($dispatcher);
Expand Down
6 changes: 6 additions & 0 deletions tests/laravel/app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public function getScoutKey()
{
return $this->getAttribute($this->getScoutKeyName());
}


public function shouldBeSearchable()
{
return $this->type != 'archive';
}
}
6 changes: 6 additions & 0 deletions tests/laravel/database/factories/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
];
});

$factory->state(Product::class, 'archive', function (Faker $faker) {
return [
'type' => 'archive',
];
});

$factory->state(Product::class, 'new', function (Faker $faker) {
return [
'type' => 'new',
Expand Down

0 comments on commit 258f310

Please sign in to comment.