diff --git a/tests/Feature/Api/PostApiPlatformMetaTest.php b/tests/Feature/Api/PostApiPlatformMetaTest.php index aa06fbd5..f54f30d2 100644 --- a/tests/Feature/Api/PostApiPlatformMetaTest.php +++ b/tests/Feature/Api/PostApiPlatformMetaTest.php @@ -48,7 +48,8 @@ ->and($meta['embeds.0.title'] ?? data_get($meta, 'embeds.0.title'))->toBe('Release'); }); -it('persists Pinterest board and TikTok privacy meta on store', function () { +it('persists per-platform meta across networks on store', function () { + $instagram = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::Instagram]); $pinterest = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::Pinterest]); $tiktok = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::TikTok]); @@ -56,14 +57,61 @@ ->postJson(route('api.posts.store'), [ 'content' => 'Cross-platform', 'platforms' => [ + ['social_account_id' => $instagram->id, 'content_type' => ContentType::InstagramFeed->value, 'meta' => ['aspect_ratio' => '4:5']], ['social_account_id' => $pinterest->id, 'content_type' => ContentType::PinterestPin->value, 'meta' => ['board_id' => 'board-99']], - ['social_account_id' => $tiktok->id, 'content_type' => ContentType::TikTokVideo->value, 'meta' => ['privacy_level' => 'SELF_ONLY']], + ['social_account_id' => $tiktok->id, 'content_type' => ContentType::TikTokVideo->value, 'meta' => ['privacy_level' => 'SELF_ONLY', 'allow_comments' => true]], ], ]) ->assertCreated(); - expect(PostPlatform::where('social_account_id', $pinterest->id)->sole()->meta['board_id'])->toBe('board-99') - ->and(PostPlatform::where('social_account_id', $tiktok->id)->sole()->meta['privacy_level'])->toBe('SELF_ONLY'); + expect(PostPlatform::where('social_account_id', $instagram->id)->sole()->meta['aspect_ratio'])->toBe('4:5') + ->and(PostPlatform::where('social_account_id', $pinterest->id)->sole()->meta['board_id'])->toBe('board-99') + ->and(PostPlatform::where('social_account_id', $tiktok->id)->sole()->meta['privacy_level'])->toBe('SELF_ONLY') + ->and(PostPlatform::where('social_account_id', $tiktok->id)->sole()->meta['allow_comments'])->toBeTrue(); +}); + +it('allows saving a Discord draft without a channel', function () { + $post = Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id]); + $platform = PostPlatform::factory()->discord()->create([ + 'post_id' => $post->id, + 'social_account_id' => $this->discordAccount->id, + 'enabled' => true, + 'meta' => [], + ]); + + $this->withHeaders($this->headers) + ->putJson(route('api.posts.update', $post), [ + 'status' => PostStatus::Draft->value, + 'platforms' => [['id' => $platform->id]], + ]) + ->assertOk(); +}); + +it('rejects publishing without TikTok privacy and Pinterest board', function () { + $pinterest = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::Pinterest]); + $tiktok = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::TikTok]); + + $post = Post::factory()->create(['workspace_id' => $this->workspace->id, 'user_id' => $this->user->id]); + $pinterestPlatform = PostPlatform::factory()->pinterest()->create([ + 'post_id' => $post->id, 'social_account_id' => $pinterest->id, 'enabled' => true, 'meta' => [], + ]); + $tiktokPlatform = PostPlatform::factory()->tiktok()->create([ + 'post_id' => $post->id, 'social_account_id' => $tiktok->id, 'enabled' => true, 'meta' => [], + ]); + + $this->withHeaders($this->headers) + ->putJson(route('api.posts.update', $post), [ + 'status' => PostStatus::Publishing->value, + 'platforms' => [ + ['id' => $pinterestPlatform->id], + ['id' => $tiktokPlatform->id], + ], + ]) + ->assertStatus(422) + ->assertJsonValidationErrors([ + 'platforms.0.meta.board_id', + 'platforms.1.meta.privacy_level', + ]); }); it('rejects publishing a Discord post without a channel', function () { diff --git a/tests/Feature/Mcp/PostPlatformMetaToolTest.php b/tests/Feature/Mcp/PostPlatformMetaToolTest.php index 2cff7b8d..5b215393 100644 --- a/tests/Feature/Mcp/PostPlatformMetaToolTest.php +++ b/tests/Feature/Mcp/PostPlatformMetaToolTest.php @@ -4,11 +4,13 @@ use App\Enums\Post\Status as PostStatus; use App\Enums\PostPlatform\ContentType; +use App\Enums\SocialAccount\Platform; use App\Enums\UserWorkspace\Role; use App\Jobs\PublishPost; use App\Mcp\Servers\TryPostServer; use App\Mcp\Tools\Post\CreatePostTool; use App\Mcp\Tools\Post\PublishPostTool; +use App\Mcp\Tools\Post\UpdatePostTool; use App\Models\Post; use App\Models\PostPlatform; use App\Models\SocialAccount; @@ -50,6 +52,65 @@ ->and(data_get($meta, 'embeds.0.title'))->toBe('Release'); }); +test('update post merges per-platform meta', function () { + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + 'status' => PostStatus::Draft, + ]); + $platform = PostPlatform::factory()->discord()->create([ + 'post_id' => $post->id, + 'social_account_id' => $this->discordAccount->id, + 'enabled' => true, + 'meta' => ['channel_name' => 'general'], + ]); + + $response = TryPostServer::actingAs($this->user) + ->tool(UpdatePostTool::class, [ + 'post_id' => $post->id, + 'platforms' => [[ + 'id' => $platform->id, + 'meta' => ['channel_id' => '444555666'], + ]], + ]); + + $response->assertOk(); + + $meta = $platform->fresh()->meta; + expect($meta['channel_id'])->toBe('444555666') + ->and($meta['channel_name'])->toBe('general'); // merged, not overwritten +}); + +test('publish guard ignores disabled platforms missing meta', function () { + Queue::fake(); + + $linkedin = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::LinkedIn]); + + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + 'status' => PostStatus::Draft, + ]); + PostPlatform::factory()->linkedin()->create([ + 'post_id' => $post->id, + 'social_account_id' => $linkedin->id, + 'enabled' => true, + ]); + // Disabled Discord with no channel must not block the publish. + PostPlatform::factory()->discord()->create([ + 'post_id' => $post->id, + 'social_account_id' => $this->discordAccount->id, + 'enabled' => false, + 'meta' => [], + ]); + + $response = TryPostServer::actingAs($this->user) + ->tool(PublishPostTool::class, ['post_id' => $post->id]); + + $response->assertOk(); + Queue::assertPushed(PublishPost::class); +}); + test('publish post rejects a Discord platform without a channel', function () { $post = Post::factory()->create([ 'workspace_id' => $this->workspace->id,