fedi-feed-router/tests/Feature/ArticleDiscoveryCommandTest.php

70 lines
No EOL
1.8 KiB
PHP

<?php
namespace Tests\Feature;
use App\Console\Commands\FetchNewArticlesCommand;
use App\Jobs\ArticleDiscoveryJob;
use App\Jobs\ArticleDiscoveryForFeedJob;
use App\Models\Feed;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class ArticleDiscoveryCommandTest extends TestCase
{
use RefreshDatabase;
public function test_command_runs_successfully_when_feeds_exist(): void
{
// Arrange
Feed::factory()->create(['is_active' => true]);
// Act & Assert
$exitCode = $this->artisan('article:refresh');
$exitCode->assertSuccessful();
// The command should complete without the "no feeds" message
$exitCode->assertExitCode(0);
}
public function test_command_does_not_dispatch_jobs_when_no_active_feeds_exist(): void
{
// Arrange
Queue::fake();
// No active feeds created
// Act
$exitCode = $this->artisan('article:refresh');
// Assert
$exitCode->assertSuccessful();
Queue::assertNotPushed(ArticleDiscoveryJob::class);
}
public function test_command_does_not_dispatch_jobs_when_only_inactive_feeds_exist(): void
{
// Arrange
Queue::fake();
Feed::factory()->create(['is_active' => false]);
// Act
$exitCode = $this->artisan('article:refresh');
// Assert
$exitCode->assertSuccessful();
Queue::assertNotPushed(ArticleDiscoveryJob::class);
}
public function test_command_logs_when_no_feeds_available(): void
{
// Arrange
Queue::fake();
// Act
$exitCode = $this->artisan('article:refresh');
// Assert
$exitCode->assertSuccessful();
$exitCode->expectsOutput('No active feeds found. Article discovery skipped.');
}
}