test,refactor: review fixes for per-platform meta parity
- Assert nested Discord meta keys (mention token/label, embed title/color) survive validated(), replacing a vacuous coalesced assertion. - Cover the MCP publish guard for TikTok privacy and Pinterest board, not just Discord. - Use assertUnprocessable() to match sibling API tests; type-hint the API UpdatePostRequest withValidator closure.
This commit is contained in:
parent
bf399c80fa
commit
40425d7bdc
3 changed files with 36 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue