7 - Add int casts on PageCrawl and tests for cascade-delete + pending scope
This commit is contained in:
parent
fe8ca7fc10
commit
f2c1fab4e4
2 changed files with 31 additions and 0 deletions
|
|
@ -28,10 +28,12 @@ class PageCrawl extends Model
|
|||
];
|
||||
|
||||
protected $casts = [
|
||||
'priority' => 'integer',
|
||||
'scheduled_for' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
'outcome' => CrawlOutcomeEnum::class,
|
||||
'locked_at' => 'datetime',
|
||||
'status_code' => 'integer',
|
||||
];
|
||||
|
||||
public function page(): BelongsTo
|
||||
|
|
|
|||
|
|
@ -79,4 +79,33 @@ public function test_page_crawl_belongs_to_a_page(): void
|
|||
$this->assertInstanceOf(Page::class, $related);
|
||||
$this->assertSame($page->id, $related->id);
|
||||
}
|
||||
|
||||
public function test_deleting_a_page_cascades_to_its_page_crawls(): void
|
||||
{
|
||||
$page = Page::factory()->create(['url' => 'https://example.com/page-cascade']);
|
||||
|
||||
PageCrawl::factory()->page($page)->create();
|
||||
PageCrawl::factory()->page($page)->successful()->create();
|
||||
PageCrawl::factory()->page($page)->failed('timeout during fetch')->create();
|
||||
|
||||
$this->assertSame(3, PageCrawl::count());
|
||||
|
||||
$page->delete();
|
||||
|
||||
$this->assertSame(0, PageCrawl::count());
|
||||
}
|
||||
|
||||
public function test_pending_crawls_are_filtered_by_null_outcome(): void
|
||||
{
|
||||
$page = Page::factory()->create(['url' => 'https://example.com/page-pending']);
|
||||
|
||||
$pending = PageCrawl::factory()->page($page)->create();
|
||||
PageCrawl::factory()->page($page)->successful()->create();
|
||||
PageCrawl::factory()->page($page)->failed('connection refused')->create();
|
||||
|
||||
$this->assertSame(1, PageCrawl::whereNull('outcome')->count());
|
||||
$this->assertSame($pending->id, PageCrawl::whereNull('outcome')->first()->id);
|
||||
|
||||
$this->assertSame(2, PageCrawl::whereNotNull('outcome')->count());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue