2026-06-16 20:39:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Enums\Post\Status as PostStatus;
|
|
|
|
|
use App\Enums\PostPlatform\ContentType;
|
|
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
|
use App\Jobs\PublishPost;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\PostPlatform;
|
|
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$result = createApiTestToken();
|
|
|
|
|
$this->user = $result['user'];
|
|
|
|
|
$this->workspace = $result['workspace'];
|
|
|
|
|
$this->plainToken = $result['plain_token'];
|
|
|
|
|
|
|
|
|
|
$this->headers = ['Authorization' => 'Bearer '.$this->plainToken];
|
|
|
|
|
|
|
|
|
|
$this->discordAccount = SocialAccount::factory()->discord()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform_user_id' => '111222333',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('persists Discord channel, mentions and embeds meta on store', function () {
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->postJson(route('api.posts.store'), [
|
|
|
|
|
'content' => 'Hello Discord',
|
|
|
|
|
'platforms' => [[
|
|
|
|
|
'social_account_id' => $this->discordAccount->id,
|
|
|
|
|
'content_type' => ContentType::DiscordMessage->value,
|
|
|
|
|
'meta' => [
|
|
|
|
|
'channel_id' => '444555666',
|
|
|
|
|
'mentions' => [['token' => '@everyone', 'label' => '@everyone']],
|
|
|
|
|
'embeds' => [['title' => 'Release', 'color' => '#5865F2']],
|
|
|
|
|
],
|
|
|
|
|
]],
|
|
|
|
|
])
|
|
|
|
|
->assertCreated();
|
|
|
|
|
|
|
|
|
|
$meta = PostPlatform::where('social_account_id', $this->discordAccount->id)->sole()->meta;
|
|
|
|
|
|
2026-06-16 21:11:29 +00:00
|
|
|
// 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');
|
2026-06-16 20:39:07 +00:00
|
|
|
});
|
|
|
|
|
|
feat(linkedin): support PDF document (carousel) posts
Add LinkedIn document posts — the swipeable PDF carousel — for both personal profiles and company pages. This is the format every major competitor exposes via native PDF upload, and the reason a trial user churned.
- New 'document' media type (application/pdf) across the upload pipeline (Type enum, HasMedia, FormRequests incl. chunked, Platform media types)
- New LinkedInDocument / LinkedInPageDocument content types: PDF-only, single-file, with a supportsDocument() flag
- Publisher flow: documents initializeUpload -> PUT -> poll AVAILABLE -> post with content.media.{id,title}; optional document_title meta (falls back to file name)
- PDF is mutually exclusive with image/video, enforced in ContentTypeCompatibleWithMedia
- Frontend: 'Document (PDF)' variant, media rules (100MB cap), composer/gallery/detail PDF cards, real PDF embed in the LinkedIn editor preview, i18n in en/es/pt-BR
- Tests: publishers (personal + page, incl. processing-failure path), enums, compatibility rule, chunked PDF upload, API + MCP document_title round-trip
LinkedIn caps documents at 100MB / 300 pages (Documents API). The page limit is enforced by LinkedIn at publish, not validated client-side.
2026-06-24 19:32:27 +00:00
|
|
|
it('persists the LinkedIn document_title meta on store', function () {
|
|
|
|
|
$linkedin = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::LinkedIn]);
|
|
|
|
|
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->postJson(route('api.posts.store'), [
|
|
|
|
|
'content' => 'Check our latest deck',
|
|
|
|
|
'platforms' => [[
|
|
|
|
|
'social_account_id' => $linkedin->id,
|
2026-06-25 00:05:09 +00:00
|
|
|
'content_type' => ContentType::LinkedInPost->value,
|
feat(linkedin): support PDF document (carousel) posts
Add LinkedIn document posts — the swipeable PDF carousel — for both personal profiles and company pages. This is the format every major competitor exposes via native PDF upload, and the reason a trial user churned.
- New 'document' media type (application/pdf) across the upload pipeline (Type enum, HasMedia, FormRequests incl. chunked, Platform media types)
- New LinkedInDocument / LinkedInPageDocument content types: PDF-only, single-file, with a supportsDocument() flag
- Publisher flow: documents initializeUpload -> PUT -> poll AVAILABLE -> post with content.media.{id,title}; optional document_title meta (falls back to file name)
- PDF is mutually exclusive with image/video, enforced in ContentTypeCompatibleWithMedia
- Frontend: 'Document (PDF)' variant, media rules (100MB cap), composer/gallery/detail PDF cards, real PDF embed in the LinkedIn editor preview, i18n in en/es/pt-BR
- Tests: publishers (personal + page, incl. processing-failure path), enums, compatibility rule, chunked PDF upload, API + MCP document_title round-trip
LinkedIn caps documents at 100MB / 300 pages (Documents API). The page limit is enforced by LinkedIn at publish, not validated client-side.
2026-06-24 19:32:27 +00:00
|
|
|
'meta' => ['document_title' => 'Q2 Report'],
|
|
|
|
|
]],
|
|
|
|
|
])
|
|
|
|
|
->assertCreated();
|
|
|
|
|
|
|
|
|
|
expect(PostPlatform::where('social_account_id', $linkedin->id)->sole()->meta['document_title'])->toBe('Q2 Report');
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-24 20:08:48 +00:00
|
|
|
it('publishes a LinkedIn document post that has a PDF', 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,
|
|
|
|
|
'content' => 'Our latest deck',
|
|
|
|
|
'media' => [[
|
|
|
|
|
'id' => 'doc-1', 'path' => 'medias/deck.pdf', 'url' => 'https://example.com/deck.pdf',
|
|
|
|
|
'type' => 'document', 'mime_type' => 'application/pdf', 'original_filename' => 'deck.pdf',
|
|
|
|
|
]],
|
|
|
|
|
]);
|
|
|
|
|
$platform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id, 'social_account_id' => $linkedin->id,
|
2026-06-25 00:05:09 +00:00
|
|
|
'platform' => Platform::LinkedIn, 'content_type' => ContentType::LinkedInPost, 'enabled' => true,
|
2026-06-24 20:08:48 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->putJson(route('api.posts.update', $post), [
|
|
|
|
|
'status' => PostStatus::Publishing->value,
|
2026-06-25 00:05:09 +00:00
|
|
|
'platforms' => [['id' => $platform->id, 'content_type' => ContentType::LinkedInPost->value]],
|
2026-06-24 20:08:48 +00:00
|
|
|
])
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
Queue::assertPushed(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
it('rejects publishing a LinkedIn post that mixes a PDF with an image', function () {
|
2026-06-24 20:08:48 +00:00
|
|
|
$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,
|
2026-06-25 00:05:09 +00:00
|
|
|
'media' => [
|
|
|
|
|
['id' => 'doc-1', 'path' => 'medias/deck.pdf', 'url' => 'https://example.com/deck.pdf', 'type' => 'document', 'mime_type' => 'application/pdf', 'original_filename' => 'deck.pdf'],
|
|
|
|
|
['id' => 'img-1', 'path' => 'medias/slide.jpg', 'url' => 'https://example.com/slide.jpg', 'type' => 'image', 'mime_type' => 'image/jpeg', 'original_filename' => 'slide.jpg'],
|
|
|
|
|
],
|
2026-06-24 20:08:48 +00:00
|
|
|
]);
|
|
|
|
|
$platform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id, 'social_account_id' => $linkedin->id,
|
|
|
|
|
'platform' => Platform::LinkedIn, 'content_type' => ContentType::LinkedInPost, 'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->putJson(route('api.posts.update', $post), [
|
|
|
|
|
'status' => PostStatus::Publishing->value,
|
|
|
|
|
'platforms' => [['id' => $platform->id, 'content_type' => ContentType::LinkedInPost->value]],
|
|
|
|
|
])
|
|
|
|
|
->assertUnprocessable()
|
|
|
|
|
->assertJsonValidationErrors(['platforms.0.content_type']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('publishes a valid LinkedIn document without resubmitting content_type', 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,
|
|
|
|
|
'content' => 'Our deck',
|
|
|
|
|
'media' => [[
|
|
|
|
|
'id' => 'doc-1', 'path' => 'medias/deck.pdf', 'url' => 'https://example.com/deck.pdf',
|
|
|
|
|
'type' => 'document', 'mime_type' => 'application/pdf', 'original_filename' => 'deck.pdf',
|
|
|
|
|
]],
|
|
|
|
|
]);
|
|
|
|
|
$platform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id, 'social_account_id' => $linkedin->id,
|
2026-06-25 00:05:09 +00:00
|
|
|
'platform' => Platform::LinkedIn, 'content_type' => ContentType::LinkedInPost, 'enabled' => true,
|
2026-06-24 20:08:48 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->putJson(route('api.posts.update', $post), [
|
|
|
|
|
'status' => PostStatus::Publishing->value,
|
|
|
|
|
'platforms' => [['id' => $platform->id]],
|
|
|
|
|
])
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
Queue::assertPushed(PublishPost::class);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-24 20:36:39 +00:00
|
|
|
it('rejects only the platform that cannot take a PDF in a multi-platform post', function () {
|
|
|
|
|
$linkedin = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::LinkedIn]);
|
|
|
|
|
$x = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::X]);
|
|
|
|
|
|
|
|
|
|
$post = Post::factory()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
'content' => 'Deck',
|
|
|
|
|
'media' => [[
|
|
|
|
|
'id' => 'doc-1', 'path' => 'medias/deck.pdf', 'url' => 'https://example.com/deck.pdf',
|
|
|
|
|
'type' => 'document', 'mime_type' => 'application/pdf', 'original_filename' => 'deck.pdf',
|
|
|
|
|
]],
|
|
|
|
|
]);
|
|
|
|
|
$linkedinPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id, 'social_account_id' => $linkedin->id,
|
2026-06-25 00:05:09 +00:00
|
|
|
'platform' => Platform::LinkedIn, 'content_type' => ContentType::LinkedInPost, 'enabled' => true,
|
2026-06-24 20:36:39 +00:00
|
|
|
]);
|
|
|
|
|
$xPlatform = PostPlatform::factory()->create([
|
|
|
|
|
'post_id' => $post->id, 'social_account_id' => $x->id,
|
|
|
|
|
'platform' => Platform::X, 'content_type' => ContentType::XPost, 'enabled' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->putJson(route('api.posts.update', $post), [
|
|
|
|
|
'status' => PostStatus::Publishing->value,
|
|
|
|
|
'platforms' => [
|
2026-06-25 00:05:09 +00:00
|
|
|
['id' => $linkedinPlatform->id, 'content_type' => ContentType::LinkedInPost->value],
|
2026-06-24 20:36:39 +00:00
|
|
|
['id' => $xPlatform->id, 'content_type' => ContentType::XPost->value],
|
|
|
|
|
],
|
|
|
|
|
])
|
|
|
|
|
->assertUnprocessable()
|
|
|
|
|
->assertJsonValidationErrors(['platforms.1.content_type'])
|
|
|
|
|
->assertJsonMissingValidationErrors(['platforms.0.content_type']);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-16 20:44:27 +00:00
|
|
|
it('persists per-platform meta across networks on store', function () {
|
|
|
|
|
$instagram = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::Instagram]);
|
2026-06-16 20:39:07 +00:00
|
|
|
$pinterest = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::Pinterest]);
|
|
|
|
|
$tiktok = SocialAccount::factory()->create(['workspace_id' => $this->workspace->id, 'platform' => Platform::TikTok]);
|
|
|
|
|
|
|
|
|
|
$this->withHeaders($this->headers)
|
|
|
|
|
->postJson(route('api.posts.store'), [
|
|
|
|
|
'content' => 'Cross-platform',
|
|
|
|
|
'platforms' => [
|
2026-06-16 20:44:27 +00:00
|
|
|
['social_account_id' => $instagram->id, 'content_type' => ContentType::InstagramFeed->value, 'meta' => ['aspect_ratio' => '4:5']],
|
2026-06-16 20:39:07 +00:00
|
|
|
['social_account_id' => $pinterest->id, 'content_type' => ContentType::PinterestPin->value, 'meta' => ['board_id' => 'board-99']],
|
2026-06-16 20:44:27 +00:00
|
|
|
['social_account_id' => $tiktok->id, 'content_type' => ContentType::TikTokVideo->value, 'meta' => ['privacy_level' => 'SELF_ONLY', 'allow_comments' => true]],
|
2026-06-16 20:39:07 +00:00
|
|
|
],
|
|
|
|
|
])
|
|
|
|
|
->assertCreated();
|
|
|
|
|
|
2026-06-16 20:44:27 +00:00
|
|
|
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],
|
|
|
|
|
],
|
|
|
|
|
])
|
2026-06-16 21:11:29 +00:00
|
|
|
->assertUnprocessable()
|
2026-06-16 20:44:27 +00:00
|
|
|
->assertJsonValidationErrors([
|
|
|
|
|
'platforms.0.meta.board_id',
|
|
|
|
|
'platforms.1.meta.privacy_level',
|
|
|
|
|
]);
|
2026-06-16 20:39:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects publishing a Discord post 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::Publishing->value,
|
|
|
|
|
'platforms' => [['id' => $platform->id]],
|
|
|
|
|
])
|
2026-06-16 21:11:29 +00:00
|
|
|
->assertUnprocessable()
|
2026-06-16 20:39:07 +00:00
|
|
|
->assertJsonValidationErrors(['platforms.0.meta.channel_id']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('publishes a Discord post when the channel is set', function () {
|
|
|
|
|
Queue::fake();
|
|
|
|
|
|
|
|
|
|
$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::Publishing->value,
|
|
|
|
|
'platforms' => [['id' => $platform->id, 'meta' => ['channel_id' => '444555666']]],
|
|
|
|
|
])
|
|
|
|
|
->assertOk();
|
|
|
|
|
|
|
|
|
|
expect($platform->fresh()->meta['channel_id'])->toBe('444555666');
|
|
|
|
|
Queue::assertPushed(PublishPost::class);
|
|
|
|
|
});
|