2026-03-08 01:18:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Actions;
|
|
|
|
|
|
|
|
|
|
use App\Actions\CreateFeedAction;
|
|
|
|
|
use App\Models\Feed;
|
|
|
|
|
use App\Models\Language;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
class CreateFeedActionTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
private CreateFeedAction $action;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
2026-03-08 14:18:28 +01:00
|
|
|
$this->action = new CreateFeedAction;
|
2026-03-08 01:18:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_creates_vrt_feed_with_correct_url(): void
|
|
|
|
|
{
|
|
|
|
|
$language = Language::factory()->create(['short_code' => 'en', 'is_active' => true]);
|
|
|
|
|
|
|
|
|
|
$feed = $this->action->execute('VRT News', 'vrt', $language->id, 'Test description');
|
|
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Feed::class, $feed);
|
|
|
|
|
$this->assertEquals('VRT News', $feed->name);
|
|
|
|
|
$this->assertEquals('https://www.vrt.be/vrtnws/en/', $feed->url);
|
|
|
|
|
$this->assertEquals('website', $feed->type);
|
|
|
|
|
$this->assertEquals('vrt', $feed->provider);
|
|
|
|
|
$this->assertEquals($language->id, $feed->language_id);
|
|
|
|
|
$this->assertEquals('Test description', $feed->description);
|
|
|
|
|
$this->assertTrue($feed->is_active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_creates_belga_feed_with_correct_url(): void
|
|
|
|
|
{
|
|
|
|
|
$language = Language::factory()->create(['short_code' => 'en', 'is_active' => true]);
|
|
|
|
|
|
|
|
|
|
$feed = $this->action->execute('Belga News', 'belga', $language->id);
|
|
|
|
|
|
2026-03-08 17:19:11 +01:00
|
|
|
$this->assertEquals('https://www.belganewsagency.eu/feed', $feed->url);
|
|
|
|
|
$this->assertEquals('rss', $feed->type);
|
2026-03-08 01:18:12 +01:00
|
|
|
$this->assertEquals('belga', $feed->provider);
|
2026-03-08 14:33:54 +01:00
|
|
|
$this->assertNull($feed->description);
|
2026-03-08 01:18:12 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-08 11:02:46 +01:00
|
|
|
public function test_creates_guardian_feed_with_correct_url(): void
|
|
|
|
|
{
|
|
|
|
|
$language = Language::factory()->create(['short_code' => 'en', 'is_active' => true]);
|
|
|
|
|
|
|
|
|
|
$feed = $this->action->execute('Guardian News', 'guardian', $language->id);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('https://www.theguardian.com/international/rss', $feed->url);
|
|
|
|
|
$this->assertEquals('rss', $feed->type);
|
|
|
|
|
$this->assertEquals('guardian', $feed->provider);
|
2026-03-08 14:33:54 +01:00
|
|
|
$this->assertNull($feed->description);
|
2026-03-08 11:02:46 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-08 01:18:12 +01:00
|
|
|
public function test_creates_vrt_feed_with_dutch_language(): void
|
|
|
|
|
{
|
|
|
|
|
$language = Language::factory()->create(['short_code' => 'nl', 'is_active' => true]);
|
|
|
|
|
|
|
|
|
|
$feed = $this->action->execute('VRT Nieuws', 'vrt', $language->id);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals('https://www.vrt.be/vrtnws/nl/', $feed->url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_returns_existing_feed_for_duplicate_url(): void
|
|
|
|
|
{
|
|
|
|
|
$language = Language::factory()->create(['short_code' => 'en', 'is_active' => true]);
|
|
|
|
|
|
|
|
|
|
$first = $this->action->execute('VRT News', 'vrt', $language->id);
|
|
|
|
|
$second = $this->action->execute('VRT News Duplicate', 'vrt', $language->id);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals($first->id, $second->id);
|
|
|
|
|
$this->assertEquals(1, Feed::count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_throws_exception_for_invalid_provider_language_combination(): void
|
|
|
|
|
{
|
|
|
|
|
$language = Language::factory()->create(['short_code' => 'fr', 'is_active' => true]);
|
|
|
|
|
|
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
|
|
|
|
|
$this->action->execute('Feed', 'belga', $language->id);
|
|
|
|
|
}
|
|
|
|
|
}
|