diff --git a/app/Console/Commands/FetchNewArticlesCommand.php b/app/Console/Commands/FetchNewArticlesCommand.php index a4eaf5d..b22b1d5 100644 --- a/app/Console/Commands/FetchNewArticlesCommand.php +++ b/app/Console/Commands/FetchNewArticlesCommand.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Jobs\ArticleDiscoveryJob; +use App\Models\Feed; use Illuminate\Console\Command; class FetchNewArticlesCommand extends Command @@ -13,6 +14,12 @@ class FetchNewArticlesCommand extends Command public function handle(): int { + if (!Feed::where('is_active', true)->exists()) { + $this->info('No active feeds found. Article discovery skipped.'); + + return self::SUCCESS; + } + ArticleDiscoveryJob::dispatch(); return self::SUCCESS; diff --git a/app/Console/Commands/PublishToLemmyCommand.php b/app/Console/Commands/PublishToLemmyCommand.php deleted file mode 100644 index deed39b..0000000 --- a/app/Console/Commands/PublishToLemmyCommand.php +++ /dev/null @@ -1,27 +0,0 @@ -firstOrFail(); - - $this->info('Queuing article for publishing: ' . $article->url); - - PublishToLemmyJob::dispatch($article); - - $this->info('Article queued successfully'); - - return self::SUCCESS; - } -} diff --git a/app/Models/FeedPlatformChannel.php b/app/Models/FeedPlatformChannel.php index a12c097..9bf99bd 100644 --- a/app/Models/FeedPlatformChannel.php +++ b/app/Models/FeedPlatformChannel.php @@ -15,13 +15,14 @@ * @property array $filters * @property Carbon $created_at * @property Carbon $updated_at + * @method static create(array $array) */ class FeedPlatformChannel extends Pivot { protected $table = 'feed_platform_channels'; - + public $incrementing = false; - + protected $fillable = [ 'feed_id', 'platform_channel_id', @@ -50,4 +51,4 @@ public function keywords(): HasMany return $this->hasMany(Keyword::class, 'feed_id', 'feed_id') ->where('platform_channel_id', $this->platform_channel_id); } -} \ No newline at end of file +} diff --git a/database/factories/ArticleFactory.php b/database/factories/ArticleFactory.php index f62004c..dbe1074 100644 --- a/database/factories/ArticleFactory.php +++ b/database/factories/ArticleFactory.php @@ -17,7 +17,13 @@ class ArticleFactory extends Factory public function definition(): array { return [ - // + 'feed_id' => \App\Models\Feed::factory(), + 'url' => $this->faker->url(), + 'title' => $this->faker->sentence(), + 'description' => $this->faker->paragraph(), + 'is_valid' => null, + 'is_duplicate' => false, + 'validated_at' => null, ]; } } diff --git a/tests/Feature/ArticleDiscoveryCommandTest.php b/tests/Feature/ArticleDiscoveryCommandTest.php new file mode 100644 index 0000000..12f9d06 --- /dev/null +++ b/tests/Feature/ArticleDiscoveryCommandTest.php @@ -0,0 +1,70 @@ +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.'); + } +} \ No newline at end of file