trypost/tests/Feature/Automation/Node/PublishNodeTest.php
Paulo Castellano b23ab0166e feat(automations): implement automation features and UI enhancements
- Added new automation-related routes and controllers for managing automations.
- Introduced automation nodes in the UI with distinct styles and interactions.
- Updated sidebar to include navigation for automations.
- Enhanced post creation logic to support automation metadata.
- Refactored content type and platform enums into types for better type safety.
- Added localization for automation-related terms in English, Spanish, and Portuguese.
- Improved error handling in various components to accommodate new features.
2026-05-24 09:17:19 -03:00

49 lines
1.7 KiB
PHP

<?php
use App\Actions\Automation\Node\RunPublishNode;
use App\Enums\Post\Status as PostStatus;
use App\Jobs\PublishPost;
use App\Models\AutomationRun;
use App\Models\Post;
use Illuminate\Support\Facades\Queue;
it('leaves post in draft when mode is draft', function () {
$post = Post::factory()->create(['status' => PostStatus::Draft]);
$run = AutomationRun::factory()->create(['generated_post_id' => $post->id]);
$result = app(RunPublishNode::class)($run, ['mode' => 'draft']);
expect($result->status->value)->toBe('completed');
expect($post->fresh()->status)->toBe(PostStatus::Draft);
});
it('schedules the post when mode is scheduled', function () {
$post = Post::factory()->create(['status' => PostStatus::Draft]);
$run = AutomationRun::factory()->create(['generated_post_id' => $post->id]);
app(RunPublishNode::class)($run, ['mode' => 'scheduled', 'scheduled_offset' => 60]);
$fresh = $post->fresh();
expect($fresh->status)->toBe(PostStatus::Scheduled);
expect($fresh->scheduled_at)->not->toBeNull();
});
it('fails when no generated post exists', function () {
$run = AutomationRun::factory()->create(['generated_post_id' => null]);
$result = app(RunPublishNode::class)($run, ['mode' => 'now']);
expect($result->status->value)->toBe('failed');
});
it('dispatches PublishPost when mode is now', function () {
Queue::fake();
$post = Post::factory()->create(['status' => PostStatus::Draft]);
$run = AutomationRun::factory()->create(['generated_post_id' => $post->id]);
app(RunPublishNode::class)($run, ['mode' => 'now']);
expect($post->fresh()->status)->toBe(PostStatus::Publishing);
Queue::assertPushed(PublishPost::class);
});