Foundational layer for the YouTube Content Creation System project, built as a fully independent domain per the earlier decision (task #47) — no foreign keys into the existing projects/tasks/ideas tables. Schema: video_projects, workflow_steps, assets, ai_providers, workflow_templates (named to avoid colliding with the existing Post-templates `templates` table). WorkflowEngine (app/Support/VideoWorkflow/) drives a project's step sequence: start/startFromTemplate, currentStep, completeStep (with optional approval gating), approveStep/rejectStep, failStep/retryStep, skipStep. It only manages state transitions — actual step execution (AI calls, rendering, etc.) is out of scope here (tasks #33+). Also fixes four Publisher classes (WordPress/Reddit/Twitter/LinkedIn) that were missing a `use App\Models\SocialAccount;` import after an earlier interface change, which broke the entire test suite at bootstrap; and PostFactory, which still set the now-removed `social_account_id` column instead of the SocialAccount pivot. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
101 lines
3.8 KiB
PHP
101 lines
3.8 KiB
PHP
<?php
|
|
|
|
use App\Models\Post;
|
|
use App\Models\SocialAccount;
|
|
use App\Support\Publishing\RedditPublisher;
|
|
use Illuminate\Support\Facades\Process;
|
|
|
|
test('it supports reddit posts only', function () {
|
|
$publisher = new RedditPublisher;
|
|
|
|
expect($publisher->supports(Post::factory()->make(['type' => 'reddit'])))->toBeTrue();
|
|
expect($publisher->supports(Post::factory()->make(['type' => 'blog'])))->toBeFalse();
|
|
});
|
|
|
|
test('it rejects a post with no title', function () {
|
|
$post = Post::factory()
|
|
->hasAttached(SocialAccount::factory()->state(['network' => 'reddit']), [], 'socialAccounts')
|
|
->create(['type' => 'reddit', 'title' => null, 'target' => 'test']);
|
|
|
|
$result = (new RedditPublisher)->publish($post);
|
|
|
|
expect($result->success)->toBeFalse();
|
|
expect($result->attempted)->toBeFalse();
|
|
expect($result->error)->toContain('no title');
|
|
});
|
|
|
|
test('it rejects a post with no target subreddit', function () {
|
|
$post = Post::factory()
|
|
->hasAttached(SocialAccount::factory()->state(['network' => 'reddit']), [], 'socialAccounts')
|
|
->create(['type' => 'reddit', 'title' => 'Hi', 'target' => null]);
|
|
|
|
$result = (new RedditPublisher)->publish($post);
|
|
|
|
expect($result->success)->toBeFalse();
|
|
expect($result->attempted)->toBeFalse();
|
|
expect($result->error)->toContain('no target subreddit');
|
|
});
|
|
|
|
test('it rejects a post with no linked reddit account', function () {
|
|
$post = Post::factory()->create(['type' => 'reddit', 'title' => 'Hi', 'target' => 'test']);
|
|
|
|
$result = (new RedditPublisher)->publish($post);
|
|
|
|
expect($result->success)->toBeFalse();
|
|
expect($result->attempted)->toBeFalse();
|
|
expect($result->error)->toContain('no linked Reddit social account');
|
|
});
|
|
|
|
test('it publishes successfully via the sidecar', function () {
|
|
Process::fake([
|
|
'*' => Process::result(output: json_encode(['success' => true, 'url' => 'https://reddit.com/r/test/comments/abc123'])),
|
|
]);
|
|
|
|
$account = SocialAccount::factory()->create(['network' => 'reddit', 'username' => 'redditor']);
|
|
$post = Post::factory()->create(['type' => 'reddit', 'title' => 'Hi', 'target' => 'test']);
|
|
$post->socialAccounts()->attach($account);
|
|
|
|
$result = (new RedditPublisher)->publish($post->fresh());
|
|
|
|
expect($result->success)->toBeTrue();
|
|
expect($result->url)->toBe('https://reddit.com/r/test/comments/abc123');
|
|
|
|
Process::assertRan(function ($process) use ($account) {
|
|
return str_contains($process->command[0], 'sidecars/reddit-post/run.sh')
|
|
&& in_array("--username={$account->username}", $process->command)
|
|
&& in_array('--subreddit=test', $process->command);
|
|
});
|
|
});
|
|
|
|
test('it treats a sidecar-reported failure as an attempted, failed publish', function () {
|
|
Process::fake([
|
|
'*' => Process::result(output: json_encode(['success' => false, 'error' => 'invalid credentials'])),
|
|
]);
|
|
|
|
$account = SocialAccount::factory()->create(['network' => 'reddit']);
|
|
$post = Post::factory()->create(['type' => 'reddit', 'title' => 'Hi', 'target' => 'test']);
|
|
$post->socialAccounts()->attach($account);
|
|
|
|
$result = (new RedditPublisher)->publish($post->fresh());
|
|
|
|
expect($result->success)->toBeFalse();
|
|
expect($result->attempted)->toBeTrue();
|
|
expect($result->error)->toBe('invalid credentials');
|
|
});
|
|
|
|
test('it fails gracefully when the sidecar output is unparseable', function () {
|
|
Process::fake([
|
|
'*' => Process::result(output: 'not json'),
|
|
]);
|
|
|
|
$account = SocialAccount::factory()->create(['network' => 'reddit']);
|
|
$post = Post::factory()->create(['type' => 'reddit', 'title' => 'Hi', 'target' => 'test']);
|
|
$post->socialAccounts()->attach($account);
|
|
|
|
$result = (new RedditPublisher)->publish($post->fresh());
|
|
|
|
expect($result->success)->toBeFalse();
|
|
expect($result->attempted)->toBeTrue();
|
|
expect($result->error)->toContain('unparseable');
|
|
});
|