Fix event flow after onboarding
This commit is contained in:
parent
188a64094a
commit
195471f8a9
5 changed files with 88 additions and 31 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\PublishToLemmyJob;
|
||||
use App\Models\Article;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class PublishToLemmyCommand extends Command
|
||||
{
|
||||
protected $signature = 'article:publish-to-lemmy';
|
||||
|
||||
protected $description = 'Queue an article for publishing to Lemmy';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$article = Article::whereDoesntHave('articlePublication')->firstOrFail();
|
||||
|
||||
$this->info('Queuing article for publishing: ' . $article->url);
|
||||
|
||||
PublishToLemmyJob::dispatch($article);
|
||||
|
||||
$this->info('Article queued successfully');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
* @property array $filters
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @method static create(array $array)
|
||||
*/
|
||||
class FeedPlatformChannel extends Pivot
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
70
tests/Feature/ArticleDiscoveryCommandTest.php
Normal file
70
tests/Feature/ArticleDiscoveryCommandTest.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?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.');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue