* Fix Facebook and Instagram-via-Facebook Page connect pagination. Follow Graph API paging.next on /me/accounts so authorized non-first Pages are found and multi-Page accounts get the picker instead of silently connecting the first result. Co-authored-by: Cursor <cursoragent@cursor.com> * Paginate Meta accounts until paging.next is exhausted. Drop the artificial 50-page cap and stop only when there is no next URL, or the same request URL repeats (broken pagination loop). Co-authored-by: Cursor <cursoragent@cursor.com> * Redact tokens in Graph pagination logs and harden test coverage. Cover happy-path and failure cases for Meta /me/accounts pagination, including mid-loop failures, invalid paging.next, and Instagram pages without a linked IG account. Co-authored-by: Cursor <cursoragent@cursor.com> * Fail closed on incomplete Meta accounts pagination. If a later /me/accounts page fails after earlier pages succeeded, throw instead of returning a truncated list that could auto-connect the wrong Page. Also revert the IG detail timeout that could wipe the whole connect list. Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify Graph pagination helpers and page fetchers. Bake the first request query into the URL, drop requestKey, and let IncompleteGraphPaginationException bubble from the controllers without catch/rethrow noise. Co-authored-by: Cursor <cursoragent@cursor.com> * Move incomplete pagination exception under Social\Meta. Colocate it with GraphPaginator so the Meta scope is clear from the namespace instead of a generic Social exception name. Co-authored-by: Cursor <cursoragent@cursor.com> * Rename pagination exception to IncompleteMetaGraphPaginationException. Keep it under Exceptions/Social with Meta in the class name instead of moving it into Services. Co-authored-by: Cursor <cursoragent@cursor.com> * Make GraphPaginator results explicit before mapping pages. Assign the paginated accounts to a variable first so the Facebook and Instagram-via-Facebook fetchers read more clearly. Co-authored-by: Cursor <cursoragent@cursor.com> * Build Meta Graph pagination URLs with Laravel Uri. Replace manual http_build_query concatenation with Uri::of()->withQuery(). Co-authored-by: Cursor <cursoragent@cursor.com> * Use Laravel HTTP and Uri helpers in Meta Graph pagination. Prefer response collect/json key access, filled(), and Uri path parsing over manual array and parse_url handling. Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify graphVersion using Uri path and str(). Drop basename and native string casts; Uri::path() already yields the Graph API version segment. Co-authored-by: Cursor <cursoragent@cursor.com> * Drop unnecessary str() around graph API config. Uri: :of() already accepts the string returned by config(). Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify GraphPaginator with Laravel helpers. Consolidate failure handling via abort(), and use collect, when, throw_if, and Uri::value() for a shorter pagination loop. Co-authored-by: Cursor <cursoragent@cursor.com> * Refactor social OAuth page/channel selection handling. Update selectPage and selectChannel methods in Facebook, Instagram, and YouTube controllers to return popup callbacks instead of redirecting on session expiration or workspace not found. Enhance HandleInertiaRequests middleware to prevent deferring onboarding progress on social OAuth popup routes. Add tests to verify behavior for expired sessions and onboarding progress. * Unify Instagram connect behind one card with a method picker. Hide the Instagram-via-Facebook grid card and offer Instagram Login vs Facebook Pages from a single network entry, matching LinkedIn. Co-authored-by: Cursor <cursoragent@cursor.com> * Move social popup onboarding assertions into connection tests. Cover the deferred-prop popup regression on Facebook, Instagram, and YouTube select routes instead of a synthetic onboarding share check. Co-authored-by: Cursor <cursoragent@cursor.com> * Stop suppressing onboarding defer on all social routes. Override onboardingProgress only in popupCallback so picker pages stay deferred and the close page does not re-hit select after session clear. Co-authored-by: Cursor <cursoragent@cursor.com> * Always open the Instagram method dialog on connect. Drop connectMethods and the single-method OAuth shortcut; the picker always offers both Login and Facebook Pages. Co-authored-by: Cursor <cursoragent@cursor.com> * Filter Instagram dialog options by enabled platforms. Keep always opening the method picker, but only list OAuth entry points that are turned on. Co-authored-by: Cursor <cursoragent@cursor.com> * Extract Instagram connect methods into a dedicated helper. Keep connectableOptions focused on shaping grid options while the enabled OAuth list lives in instagramConnectMethods(). Co-authored-by: Cursor <cursoragent@cursor.com> * Harden Meta Graph pagination and localize Instagram connect copy. Fail closed on Graph request errors and pathological paging, keep Instagram connect going when profile detail lookups time out, and translate the Instagram method dialog strings. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
189 lines
9 KiB
PHP
189 lines
9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Enums\Media\Type as MediaType;
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
test('platform has correct labels', function () {
|
|
expect(Platform::LinkedIn->label())->toBe('LinkedIn');
|
|
expect(Platform::LinkedInPage->label())->toBe('LinkedIn Page');
|
|
expect(Platform::X->label())->toBe('X');
|
|
expect(Platform::TikTok->label())->toBe('TikTok');
|
|
expect(Platform::YouTube->label())->toBe('YouTube Shorts');
|
|
expect(Platform::Facebook->label())->toBe('Facebook Page');
|
|
expect(Platform::Instagram->label())->toBe('Instagram');
|
|
expect(Platform::InstagramFacebook->label())->toBe('Instagram (Facebook Business)');
|
|
expect(Platform::Threads->label())->toBe('Threads');
|
|
expect(Platform::Pinterest->label())->toBe('Pinterest');
|
|
expect(Platform::Bluesky->label())->toBe('Bluesky');
|
|
expect(Platform::Mastodon->label())->toBe('Mastodon');
|
|
});
|
|
|
|
test('platform has correct colors', function () {
|
|
expect(Platform::LinkedIn->color())->toBe('#0A66C2');
|
|
expect(Platform::LinkedInPage->color())->toBe('#0A66C2');
|
|
expect(Platform::X->color())->toBe('#000000');
|
|
expect(Platform::TikTok->color())->toBe('#000000');
|
|
expect(Platform::YouTube->color())->toBe('#FF0000');
|
|
expect(Platform::Facebook->color())->toBe('#1877F2');
|
|
expect(Platform::Instagram->color())->toBe('#E4405F');
|
|
expect(Platform::Threads->color())->toBe('#000000');
|
|
expect(Platform::Pinterest->color())->toBe('#E60023');
|
|
expect(Platform::Bluesky->color())->toBe('#0085FF');
|
|
expect(Platform::Mastodon->color())->toBe('#6364FF');
|
|
});
|
|
|
|
test('platform has correct allowed media types', function () {
|
|
expect(Platform::LinkedIn->allowedMediaTypes())->toContain(MediaType::Image, MediaType::Video, MediaType::Document);
|
|
expect(Platform::LinkedInPage->allowedMediaTypes())->toContain(MediaType::Image, MediaType::Video, MediaType::Document);
|
|
expect(Platform::X->allowedMediaTypes())->toContain(MediaType::Image, MediaType::Video);
|
|
expect(Platform::X->allowedMediaTypes())->not->toContain(MediaType::Document);
|
|
expect(Platform::TikTok->allowedMediaTypes())->toBe([MediaType::Video]);
|
|
expect(Platform::YouTube->allowedMediaTypes())->toBe([MediaType::Video]);
|
|
expect(Platform::Instagram->allowedMediaTypes())->toContain(MediaType::Image, MediaType::Video);
|
|
});
|
|
|
|
test('platform has correct max images', function () {
|
|
expect(Platform::LinkedIn->maxImages())->toBe(10);
|
|
expect(Platform::X->maxImages())->toBe(4);
|
|
expect(Platform::TikTok->maxImages())->toBe(0);
|
|
expect(Platform::YouTube->maxImages())->toBe(0);
|
|
expect(Platform::Facebook->maxImages())->toBe(10);
|
|
expect(Platform::Instagram->maxImages())->toBe(10);
|
|
expect(Platform::Threads->maxImages())->toBe(10);
|
|
expect(Platform::Pinterest->maxImages())->toBe(5);
|
|
expect(Platform::Bluesky->maxImages())->toBe(4);
|
|
expect(Platform::Mastodon->maxImages())->toBe(4);
|
|
});
|
|
|
|
test('platform has correct max content length', function () {
|
|
expect(Platform::LinkedIn->maxContentLength())->toBe(3000);
|
|
expect(Platform::X->maxContentLength())->toBe(280);
|
|
expect(Platform::TikTok->maxContentLength())->toBe(2200);
|
|
expect(Platform::YouTube->maxContentLength())->toBe(100);
|
|
expect(Platform::Facebook->maxContentLength())->toBe(10000);
|
|
expect(Platform::Instagram->maxContentLength())->toBe(2200);
|
|
expect(Platform::Threads->maxContentLength())->toBe(500);
|
|
expect(Platform::Pinterest->maxContentLength())->toBe(800);
|
|
expect(Platform::Bluesky->maxContentLength())->toBe(300);
|
|
expect(Platform::Mastodon->maxContentLength())->toBe(500);
|
|
});
|
|
|
|
test('platform supports text only correctly', function () {
|
|
expect(Platform::LinkedIn->supportsTextOnly())->toBeTrue();
|
|
expect(Platform::LinkedInPage->supportsTextOnly())->toBeTrue();
|
|
expect(Platform::X->supportsTextOnly())->toBeTrue();
|
|
expect(Platform::Facebook->supportsTextOnly())->toBeTrue();
|
|
expect(Platform::Threads->supportsTextOnly())->toBeTrue();
|
|
expect(Platform::Bluesky->supportsTextOnly())->toBeTrue();
|
|
expect(Platform::Mastodon->supportsTextOnly())->toBeTrue();
|
|
|
|
expect(Platform::TikTok->supportsTextOnly())->toBeFalse();
|
|
expect(Platform::YouTube->supportsTextOnly())->toBeFalse();
|
|
expect(Platform::Instagram->supportsTextOnly())->toBeFalse();
|
|
expect(Platform::Pinterest->supportsTextOnly())->toBeFalse();
|
|
});
|
|
|
|
test('platform exposes the correct default token TTL fallback', function () {
|
|
// X access tokens live 2 hours.
|
|
expect(Platform::X->defaultTokenTtlSeconds())->toBe(7200);
|
|
|
|
// Instagram and Threads use Meta's 60-day long-lived token.
|
|
expect(Platform::Instagram->defaultTokenTtlSeconds())->toBe(5184000);
|
|
expect(Platform::Threads->defaultTokenTtlSeconds())->toBe(5184000);
|
|
|
|
// Networks that always return expires_in, set a fixed lifetime directly, or
|
|
// never expire have no fallback here.
|
|
expect(Platform::LinkedIn->defaultTokenTtlSeconds())->toBeNull();
|
|
expect(Platform::TikTok->defaultTokenTtlSeconds())->toBeNull();
|
|
expect(Platform::YouTube->defaultTokenTtlSeconds())->toBeNull();
|
|
expect(Platform::Pinterest->defaultTokenTtlSeconds())->toBeNull();
|
|
expect(Platform::Bluesky->defaultTokenTtlSeconds())->toBeNull();
|
|
expect(Platform::Facebook->defaultTokenTtlSeconds())->toBeNull();
|
|
});
|
|
|
|
test('platform is enabled by default', function () {
|
|
expect(Platform::LinkedIn->isEnabled())->toBeTrue();
|
|
expect(Platform::Instagram->isEnabled())->toBeTrue();
|
|
});
|
|
|
|
test('platform can be disabled via config', function () {
|
|
config(['trypost.platforms.linkedin.enabled' => false]);
|
|
|
|
expect(Platform::LinkedIn->isEnabled())->toBeFalse();
|
|
});
|
|
|
|
test('linkedin pages and instagram facebook are not directly connectable', function () {
|
|
expect(Platform::LinkedInPage->isConnectable())->toBeFalse();
|
|
expect(Platform::LinkedIn->isConnectable())->toBeTrue();
|
|
expect(Platform::InstagramFacebook->isConnectable())->toBeFalse();
|
|
expect(Platform::Instagram->isConnectable())->toBeTrue();
|
|
});
|
|
|
|
test('the linkedin card is connectable while either capability is enabled', function () {
|
|
config(['trypost.platforms.linkedin.enabled' => true, 'trypost.platforms.linkedin-page.enabled' => false]);
|
|
expect(Platform::LinkedIn->isConnectable())->toBeTrue();
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => false, 'trypost.platforms.linkedin-page.enabled' => true]);
|
|
expect(Platform::LinkedIn->isConnectable())->toBeTrue();
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => false, 'trypost.platforms.linkedin-page.enabled' => false]);
|
|
expect(Platform::LinkedIn->isConnectable())->toBeFalse();
|
|
|
|
// A company page never gets its own card regardless of toggles.
|
|
config(['trypost.platforms.linkedin-page.enabled' => true]);
|
|
expect(Platform::LinkedInPage->isConnectable())->toBeFalse();
|
|
});
|
|
|
|
test('the instagram card is connectable while either capability is enabled', function () {
|
|
config(['trypost.platforms.instagram.enabled' => true, 'trypost.platforms.instagram-facebook.enabled' => false]);
|
|
expect(Platform::Instagram->isConnectable())->toBeTrue();
|
|
|
|
config(['trypost.platforms.instagram.enabled' => false, 'trypost.platforms.instagram-facebook.enabled' => true]);
|
|
expect(Platform::Instagram->isConnectable())->toBeTrue();
|
|
|
|
config(['trypost.platforms.instagram.enabled' => false, 'trypost.platforms.instagram-facebook.enabled' => false]);
|
|
expect(Platform::Instagram->isConnectable())->toBeFalse();
|
|
|
|
// Via-Facebook never gets its own card regardless of toggles.
|
|
config(['trypost.platforms.instagram-facebook.enabled' => true]);
|
|
expect(Platform::InstagramFacebook->isConnectable())->toBeFalse();
|
|
});
|
|
|
|
test('connectable options are sorted alphabetically by label', function () {
|
|
$labels = array_column(Platform::connectableOptions(), 'label');
|
|
|
|
$sorted = $labels;
|
|
natcasesort($sorted);
|
|
|
|
expect($labels)->toBe(array_values($sorted));
|
|
});
|
|
|
|
test('connectable options include a single instagram card and omit the facebook variant', function () {
|
|
$values = array_column(Platform::connectableOptions(), 'value');
|
|
|
|
expect($values)->toContain(Platform::Instagram->value)
|
|
->and($values)->not->toContain(Platform::InstagramFacebook->value);
|
|
});
|
|
|
|
test('instagram connectable option lists only enabled connect methods', function () {
|
|
config(['trypost.platforms.instagram.enabled' => true, 'trypost.platforms.instagram-facebook.enabled' => false]);
|
|
|
|
expect(Platform::instagramConnectMethods())->toBe([Platform::Instagram->value]);
|
|
|
|
$instagram = collect(Platform::connectableOptions())->firstWhere('value', Platform::Instagram->value);
|
|
|
|
expect($instagram['connect_methods'])->toBe([Platform::Instagram->value]);
|
|
|
|
config(['trypost.platforms.instagram.enabled' => false, 'trypost.platforms.instagram-facebook.enabled' => true]);
|
|
|
|
expect(Platform::instagramConnectMethods())->toBe([Platform::InstagramFacebook->value]);
|
|
|
|
config(['trypost.platforms.instagram.enabled' => true, 'trypost.platforms.instagram-facebook.enabled' => true]);
|
|
|
|
expect(Platform::instagramConnectMethods())->toBe([
|
|
Platform::Instagram->value,
|
|
Platform::InstagramFacebook->value,
|
|
]);
|
|
});
|