/** @test */
public function a_job_is_indexed_to_algolia()
{
$this->withoutExceptionHandling();
Event::fake();
Mail::fake();
Mail::assertNothingSent();
Search::assertEmpty();
Storage::fake('media');
$user = factory(User::class)->create();
$job = $this->actingAs($user)
->post('/jobs', $this->validParams(['document' => UploadedFile::fake()->image('lumber.jpg')]))
->assertRedirect('/searchjobs');
// The error occurs with the 'document' above
Search::assertSynced($job);
Was wondering if anyone had tried to test using the Spatie Media-Library?
The challenge is sending a Laravel Scout toSearchableArray() index to algolia with $job details and the thumbnail path. If the media-library saved a path in the $job table this would be easy. However, that package uses separate Media table.
This package Sti3bas / laravel-scout-array-driver helps determine if the searchableArray() has been synced among many other handy assertions.
From what I gather above the error is expecting a 'document' file name. However, I'm at a loss with how to test creating a job and uploading a file.
Here's the controller which creates the job:
// JobsController.php
// validation
// saving job object
// below takes job_id, stores media/documents which the path can later be retrieved and synced to Algolia
foreach ($request->input('document', []) as $file) {
$job->addMedia(storage_path('medialibrary/temp/' . $file))
->preservingOriginal()
->toMediaCollection('document', 'media');
}