fedi-feed-router/backend/tests/Feature/Http/Console/Commands/FetchNewArticlesCommandTest.php

74 lines
2 KiB
PHP
Raw Normal View History

2025-07-06 16:51:09 +02:00
<?php
2025-08-06 21:54:47 +02:00
namespace Tests\Feature\Http\Console\Commands;
2025-07-06 16:51:09 +02:00
use App\Jobs\ArticleDiscoveryJob;
use App\Models\Feed;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
2025-07-07 02:48:46 +02:00
use Illuminate\Testing\PendingCommand;
2025-07-06 16:51:09 +02:00
use Tests\TestCase;
2025-08-06 21:54:47 +02:00
class FetchNewArticlesCommandTest extends TestCase
2025-07-06 16:51:09 +02:00
{
use RefreshDatabase;
public function test_command_runs_successfully_when_feeds_exist(): void
{
// Arrange
Feed::factory()->create(['is_active' => true]);
// Act & Assert
2025-07-07 02:48:46 +02:00
/** @var PendingCommand $exitCode */
2025-07-06 16:51:09 +02:00
$exitCode = $this->artisan('article:refresh');
$exitCode->assertSuccessful();
2025-08-06 21:54:47 +02:00
2025-07-06 16:51:09 +02:00
// 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
2025-07-07 02:48:46 +02:00
/** @var PendingCommand $exitCode */
2025-07-06 16:51:09 +02:00
$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
2025-07-07 02:48:46 +02:00
/** @var PendingCommand $exitCode */
2025-07-06 16:51:09 +02:00
$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
2025-07-07 02:48:46 +02:00
/** @var PendingCommand $exitCode */
2025-07-06 16:51:09 +02:00
$exitCode = $this->artisan('article:refresh');
// Assert
$exitCode->assertSuccessful();
$exitCode->expectsOutput('No active feeds found. Article discovery skipped.');
}
2025-08-06 21:54:47 +02:00
}