Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Make the social connect tests assert where the redirect actually goes (#345)
Paulo Castellanoed7365a54648
diff --git a/tests/Feature/Social/DiscordControllerTest.php b/tests/Feature/Social/DiscordControllerTest.phpindex 4dd0a3fd6..58d04223c 100644--- a/tests/Feature/Social/DiscordControllerTest.php+++ b/tests/Feature/Social/DiscordControllerTest.php@@ -19,6 +19,16 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('discord authorize url asks for the bot scope and leaves the server picker open', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.discord.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://discord.com/api/oauth2/authorize')+ ->toContain('scope=bot identify guilds')+ ->toContain('permissions=248832')+ ->not->toContain('disable_guild_select');+});+test('discord connect redirects to the oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('scopes')->andReturnSelf();@@ -30,9 +40,8 @@ test('discord connect redirects to the oauth provider', function () {Socialite::shouldReceive('driver')->with('discord')->andReturn($driverMock);$this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.discord.connect'))- ->assertStatus(409); // Inertia::location+ ->assertRedirect('https://discord.com/api/oauth2/authorize?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});diff --git a/tests/Feature/Social/FacebookControllerTest.php b/tests/Feature/Social/FacebookControllerTest.phpindex 5c30e3122..d6507392e 100644--- a/tests/Feature/Social/FacebookControllerTest.php+++ b/tests/Feature/Social/FacebookControllerTest.php@@ -23,6 +23,14 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('facebook authorize url reopens the page selection', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.facebook.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://www.facebook.com/')+ ->toContain('auth_type=rerequest');+});+test('facebook connect redirects to oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('usingGraphVersion')->andReturnSelf();@@ -37,10 +45,9 @@ test('facebook connect redirects to oauth provider', function () {->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.facebook.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://www.facebook.com/v25.0/dialog/oauth?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});@@ -657,10 +664,9 @@ test('facebook connect remembers the reconnect account from the query string', f->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.facebook.connect', ['reconnect' => $account->id]));- $response->assertStatus(409);+ $response->assertRedirect('https://www.facebook.com/v25.0/dialog/oauth?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id)->and(session('social_reconnect_id'))->toBe($account->id);@@ -685,9 +691,8 @@ test('facebook connect ignores a reconnect id from another workspace', function->andReturn($driverMock);$this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.facebook.connect', ['reconnect' => $foreign->id]))- ->assertStatus(409);+ ->assertRedirect('https://www.facebook.com/v25.0/dialog/oauth?test=1');expect(session('social_reconnect_id'))->toBeNull();});@@ -712,9 +717,8 @@ test('facebook connect ignores a reconnect id from another network', function ()->andReturn($driverMock);$this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.facebook.connect', ['reconnect' => $linkedin->id]))- ->assertStatus(409);+ ->assertRedirect('https://www.facebook.com/v25.0/dialog/oauth?test=1');expect(session('social_reconnect_id'))->toBeNull();});diff --git a/tests/Feature/Social/InstagramControllerTest.php b/tests/Feature/Social/InstagramControllerTest.phpindex a2a6d48b2..3efef9962 100644--- a/tests/Feature/Social/InstagramControllerTest.php+++ b/tests/Feature/Social/InstagramControllerTest.php@@ -43,10 +43,9 @@ test('instagram connect redirects to oauth provider', function () {$this->withoutExceptionHandling();$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.instagram.connect'));- $response->assertStatus(409);+ $response->assertRedirect('https://www.instagram.com/oauth/authorize?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});diff --git a/tests/Feature/Social/InstagramFacebookControllerTest.php b/tests/Feature/Social/InstagramFacebookControllerTest.phpindex ad11d10b3..b17c04068 100644--- a/tests/Feature/Social/InstagramFacebookControllerTest.php+++ b/tests/Feature/Social/InstagramFacebookControllerTest.php@@ -22,6 +22,14 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('instagram-facebook authorize url reopens the page selection', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.instagram-facebook.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://www.facebook.com/')+ ->toContain('auth_type=rerequest');+});+test('instagram-facebook connect redirects to oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('usingGraphVersion')->andReturnSelf();@@ -37,10 +45,9 @@ test('instagram-facebook connect redirects to oauth provider', function () {->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.instagram-facebook.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://www.facebook.com/v25.0/dialog/oauth?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});diff --git a/tests/Feature/Social/LinkedInControllerTest.php b/tests/Feature/Social/LinkedInControllerTest.phpindex a7188285f..43c3e9f10 100644--- a/tests/Feature/Social/LinkedInControllerTest.php+++ b/tests/Feature/Social/LinkedInControllerTest.php@@ -38,6 +38,15 @@ function linkedInSocialiteUser(string $id = 'person-123'): SocialiteUserreturn $socialiteUser;}+test('linkedin authorize url carries the member and organization scopes', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.linkedin.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://www.linkedin.com/oauth/v2/authorization')+ ->toContain('w_member_social')+ ->toContain('rw_organization_admin');+});+test('linkedin connect redirects to oauth provider via the openid driver', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('scopes')->andReturnSelf();@@ -50,10 +59,9 @@ test('linkedin connect redirects to oauth provider via the openid driver', funct->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.linkedin.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://www.linkedin.com/oauth/v2/authorization?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});@@ -82,7 +90,6 @@ function captureLinkedInConnectScopes(object $test): arraySocialite::shouldReceive('driver')->with('linkedin-openid')->andReturn($driverMock);$test->actingAs($test->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.linkedin.connect'));return $captured;diff --git a/tests/Feature/Social/MastodonControllerTest.php b/tests/Feature/Social/MastodonControllerTest.phpindex 2d0bfa140..d75f44032 100644--- a/tests/Feature/Social/MastodonControllerTest.php+++ b/tests/Feature/Social/MastodonControllerTest.php@@ -36,12 +36,12 @@ test('user can initiate mastodon oauth flow', function () {]);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->post(route('app.social.mastodon.authorize'), ['instance' => 'https://mastodon.social',]);- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ expect($response->headers->get('Location'))+ ->toStartWith('https://mastodon.social/oauth/authorize');expect(session('mastodon_instance'))->toBe('https://mastodon.social');expect(session('mastodon_client_id'))->toBe('test-client-id');@@ -244,12 +244,12 @@ test('mastodon works with custom instances', function () {]);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->post(route('app.social.mastodon.authorize'), ['instance' => 'https://techhub.social',]);- $response->assertStatus(409); // Inertia::location with X-Inertia header+ expect($response->headers->get('Location'))+ ->toStartWith('https://techhub.social/oauth/authorize');expect(session('mastodon_instance'))->toBe('https://techhub.social');});diff --git a/tests/Feature/Social/PinterestControllerTest.php b/tests/Feature/Social/PinterestControllerTest.phpindex 7d40926e7..d9d70f18d 100644--- a/tests/Feature/Social/PinterestControllerTest.php+++ b/tests/Feature/Social/PinterestControllerTest.php@@ -19,6 +19,15 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('pinterest authorize url carries the publishing scopes', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.pinterest.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://www.pinterest.com/oauth')+ ->toContain('boards:read')+ ->toContain('pins:write');+});+test('pinterest connect redirects to oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('scopes')->andReturnSelf();@@ -32,10 +41,9 @@ test('pinterest connect redirects to oauth provider', function () {->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.pinterest.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://www.pinterest.com/oauth?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});diff --git a/tests/Feature/Social/ThreadsControllerTest.php b/tests/Feature/Social/ThreadsControllerTest.phpindex 033fe3085..eb286575c 100644--- a/tests/Feature/Social/ThreadsControllerTest.php+++ b/tests/Feature/Social/ThreadsControllerTest.php@@ -20,10 +20,10 @@ beforeEach(function () {test('threads connect redirects to oauth', function () {$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.threads.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ expect($response->headers->get('Location'))+ ->toStartWith('https://threads.net/oauth/authorize');expect(session('social_connect_workspace'))->toBe($this->workspace->id);expect(session('threads_oauth_state'))->not->toBeNull();diff --git a/tests/Feature/Social/TikTokControllerTest.php b/tests/Feature/Social/TikTokControllerTest.phpindex 2e91da566..ecb6ca2fe 100644--- a/tests/Feature/Social/TikTokControllerTest.php+++ b/tests/Feature/Social/TikTokControllerTest.php@@ -19,6 +19,14 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('tiktok authorize url disables auto auth', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.tiktok.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://www.tiktok.com/v2/auth/authorize')+ ->toContain('disable_auto_auth=1');+});+test('tiktok connect redirects to oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('scopes')->andReturnSelf();@@ -32,10 +40,9 @@ test('tiktok connect redirects to oauth provider', function () {->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.tiktok.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://www.tiktok.com/v2/auth/authorize?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});@@ -202,9 +209,8 @@ test('tiktok connect carries a reconnect id into the session', function () {Socialite::shouldReceive('driver')->with('tiktok')->andReturn($driverMock);$this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.tiktok.connect', ['reconnect' => $account->id]))- ->assertStatus(409);+ ->assertRedirect('https://www.tiktok.com/v2/auth/authorize?test=1');expect(session('social_reconnect_id'))->toBe($account->id);});diff --git a/tests/Feature/Social/XControllerTest.php b/tests/Feature/Social/XControllerTest.phpindex 2c46fd224..1c343e0f9 100644--- a/tests/Feature/Social/XControllerTest.php+++ b/tests/Feature/Social/XControllerTest.php@@ -19,6 +19,15 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('x authorize url uses the current host and pkce', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.x.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://x.com/i/oauth2/authorize')+ ->toContain('code_challenge_method=S256')+ ->toContain('offline.access');+});+test('x connect redirects to oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('scopes')->andReturnSelf();@@ -32,10 +41,9 @@ test('x connect redirects to oauth provider', function () {->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.x.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://twitter.com/i/oauth2/authorize?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});diff --git a/tests/Feature/Social/YouTubeControllerTest.php b/tests/Feature/Social/YouTubeControllerTest.phpindex 456ff201c..cb9ac8000 100644--- a/tests/Feature/Social/YouTubeControllerTest.php+++ b/tests/Feature/Social/YouTubeControllerTest.php@@ -21,6 +21,14 @@ beforeEach(function () {$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);});+test('youtube authorize url offers the account chooser', function () {+ $response = $this->actingAs($this->user)->get(route('app.social.youtube.connect'));++ expect(urldecode((string) $response->headers->get('Location')))+ ->toStartWith('https://accounts.google.com/')+ ->toContain('prompt=select_account consent');+});+test('youtube connect redirects to oauth provider', function () {$driverMock = Mockery::mock();$driverMock->shouldReceive('scopes')->andReturnSelf();@@ -38,10 +46,9 @@ test('youtube connect redirects to oauth provider', function () {->andReturn($driverMock);$response = $this->actingAs($this->user)- ->withHeader('X-Inertia', 'true')->get(route('app.social.youtube.connect'));- $response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header+ $response->assertRedirect('https://accounts.google.com/o/oauth2/v2/auth?test=1');expect(session('social_connect_workspace'))->toBe($this->workspace->id);});