40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Jobs;
|
|
|
|
use App\Jobs\ProcessCrawlJob;
|
|
use App\Models\Page;
|
|
use App\Models\PageCrawl;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Tests\TestCase;
|
|
|
|
class ProcessCrawlJobTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_creating_a_page_crawl_dispatches_process_crawl_job(): void
|
|
{
|
|
Queue::fake();
|
|
|
|
$page = Page::factory()->createQuietly(['url' => 'https://example.com/article']);
|
|
PageCrawl::factory()->page($page)->create();
|
|
|
|
Queue::assertPushed(ProcessCrawlJob::class);
|
|
}
|
|
|
|
public function test_dispatched_job_carries_the_correct_page_crawl(): void
|
|
{
|
|
Queue::fake();
|
|
|
|
$page = Page::factory()->createQuietly(['url' => 'https://example.com/article']);
|
|
$crawl = PageCrawl::factory()->page($page)->create();
|
|
|
|
Queue::assertPushed(
|
|
ProcessCrawlJob::class,
|
|
fn (ProcessCrawlJob $job) => $job->pageCrawl->id === $crawl->id,
|
|
);
|
|
}
|
|
}
|