assertInstanceOf(Page::class, $page); $this->assertSame('https://example.com/article', $page->url); $this->assertSame(PageStatusEnum::Discovered, $page->status); $this->assertNull($page->instance_id); $this->assertDatabaseHas('pages', ['url' => 'https://example.com/article']); } public function test_creates_page_with_provided_instance_id(): void { $instance = Instance::factory() ->type(InstanceType::Mastodon) ->enabled() ->create(); $action = new RegisterDiscoveredPageAction; $page = $action('https://example.com/fediverse-post', instanceId: $instance->id); $this->assertInstanceOf(Page::class, $page); $this->assertSame($instance->id, $page->instance_id); $this->assertDatabaseHas('pages', [ 'url' => 'https://example.com/fediverse-post', 'instance_id' => $instance->id, ]); } public function test_returns_existing_page_when_url_already_exists(): void { $existing = Page::factory()->createQuietly([ 'url' => 'https://example.com/seen-before', 'status' => PageStatusEnum::Discovered, ]); $action = new RegisterDiscoveredPageAction; $returned = $action('https://example.com/seen-before'); $this->assertSame($existing->id, $returned->id); $this->assertDatabaseCount('pages', 1); } public function test_existing_page_status_not_overwritten_on_duplicate_call(): void { Page::factory()->createQuietly([ 'url' => 'https://example.com/already-fetched', 'status' => PageStatusEnum::Fetched, ]); $action = new RegisterDiscoveredPageAction; $returned = $action('https://example.com/already-fetched'); $this->assertSame(PageStatusEnum::Fetched, $returned->status); $this->assertDatabaseHas('pages', [ 'url' => 'https://example.com/already-fetched', 'status' => PageStatusEnum::Fetched, ]); } }