jonnybarnes.uk/tests/Unit/Jobs/ProcessBookmarkJobTest.php
Jonny Barnes d7da42b626
Some checks failed
PHP Unit / PHPUnit test suite (pull_request) Has been cancelled
Laravel Pint / Laravel Pint (pull_request) Has been cancelled
Host images locally
We don’t need the complexity of S3. Sepcifically the complexity of
managing my own AWS account, flysystem made the Laravel side easy.

A command is added to copy the the S3 files over to local storage.
2024-10-25 20:40:52 +01:00

60 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Jobs;
use App\Exceptions\InternetArchiveException;
use App\Jobs\ProcessBookmark;
use App\Jobs\SaveScreenshot;
use App\Models\Bookmark;
use App\Services\BookmarkService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class ProcessBookmarkJobTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function archiveLinkIsSavedByJobAndScreenshotJobIsQueued(): void
{
Queue::fake();
$bookmark = Bookmark::factory()->create();
$service = $this->createMock(BookmarkService::class);
$service->method('getArchiveLink')
->willReturn('https://web.archive.org/web/1234');
$this->app->instance(BookmarkService::class, $service);
$job = new ProcessBookmark($bookmark);
$job->handle();
$this->assertDatabaseHas('bookmarks', [
'archive' => 'https://web.archive.org/web/1234',
]);
Queue::assertPushed(SaveScreenshot::class);
}
/** @test */
public function archiveLinkSavedAsNullWhenExceptionThrown(): void
{
Queue::fake();
$bookmark = Bookmark::factory()->create();
$service = $this->createMock(BookmarkService::class);
$service->method('getArchiveLink')
->will($this->throwException(new InternetArchiveException));
$this->app->instance(BookmarkService::class, $service);
$job = new ProcessBookmark($bookmark);
$job->handle();
$this->assertDatabaseHas('bookmarks', [
'id' => $bookmark->id,
'archive' => null,
]);
}
}