diff --git a/app/Http/Requests/Api/Post/UpdatePostRequest.php b/app/Http/Requests/Api/Post/UpdatePostRequest.php index 02fa34d0..7d3ef18e 100644 --- a/app/Http/Requests/Api/Post/UpdatePostRequest.php +++ b/app/Http/Requests/Api/Post/UpdatePostRequest.php @@ -68,7 +68,7 @@ public function rules(): array public function withValidator(Validator $validator): void { - $validator->after(function ($validator): void { + $validator->after(function (Validator $validator): void { if (! in_array($this->input('status'), [Status::Scheduled->value, Status::Publishing->value], true)) { return; } diff --git a/tests/Feature/Api/PostApiPlatformMetaTest.php b/tests/Feature/Api/PostApiPlatformMetaTest.php index f54f30d2..4865df41 100644 --- a/tests/Feature/Api/PostApiPlatformMetaTest.php +++ b/tests/Feature/Api/PostApiPlatformMetaTest.php @@ -43,9 +43,12 @@ $meta = PostPlatform::where('social_account_id', $this->discordAccount->id)->sole()->meta; - expect($meta['channel_id'])->toBe('444555666') - ->and($meta['mentions'])->toHaveCount(1) - ->and($meta['embeds.0.title'] ?? data_get($meta, 'embeds.0.title'))->toBe('Release'); + // Assert nested keys survive validated() — the exact stripping bug this PR fixes. + expect(data_get($meta, 'channel_id'))->toBe('444555666') + ->and(data_get($meta, 'mentions.0.token'))->toBe('@everyone') + ->and(data_get($meta, 'mentions.0.label'))->toBe('@everyone') + ->and(data_get($meta, 'embeds.0.title'))->toBe('Release') + ->and(data_get($meta, 'embeds.0.color'))->toBe('#5865F2'); }); it('persists per-platform meta across networks on store', function () { @@ -107,7 +110,7 @@ ['id' => $tiktokPlatform->id], ], ]) - ->assertStatus(422) + ->assertUnprocessable() ->assertJsonValidationErrors([ 'platforms.0.meta.board_id', 'platforms.1.meta.privacy_level', @@ -128,7 +131,7 @@ 'status' => PostStatus::Publishing->value, 'platforms' => [['id' => $platform->id]], ]) - ->assertStatus(422) + ->assertUnprocessable() ->assertJsonValidationErrors(['platforms.0.meta.channel_id']); }); diff --git a/tests/Feature/Mcp/PostPlatformMetaToolTest.php b/tests/Feature/Mcp/PostPlatformMetaToolTest.php index 5b215393..43f6ee26 100644 --- a/tests/Feature/Mcp/PostPlatformMetaToolTest.php +++ b/tests/Feature/Mcp/PostPlatformMetaToolTest.php @@ -130,6 +130,33 @@ $response->assertHasErrors([__('posts.form.discord.channel_required')]); }); +test('publish guard enforces required meta for TikTok and Pinterest', function (string $factoryState, string $field, string $messageKey) { + $account = SocialAccount::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'platform' => $factoryState === 'tiktok' ? Platform::TikTok : Platform::Pinterest, + ]); + + $post = Post::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'user_id' => $this->user->id, + 'status' => PostStatus::Draft, + ]); + PostPlatform::factory()->{$factoryState}()->create([ + 'post_id' => $post->id, + 'social_account_id' => $account->id, + 'enabled' => true, + 'meta' => [], + ]); + + $response = TryPostServer::actingAs($this->user) + ->tool(PublishPostTool::class, ['post_id' => $post->id]); + + $response->assertHasErrors([__($messageKey)]); +})->with([ + 'tiktok' => ['tiktok', 'privacy_level', 'posts.form.tiktok.privacy_required'], + 'pinterest' => ['pinterest', 'board_id', 'posts.form.pinterest.board_required'], +]); + test('publish post succeeds for a Discord platform with a channel', function () { Queue::fake();