diff --git a/app/Http/Controllers/App/WorkspaceController.php b/app/Http/Controllers/App/WorkspaceController.php index 8fecc6b1..088e8606 100644 --- a/app/Http/Controllers/App/WorkspaceController.php +++ b/app/Http/Controllers/App/WorkspaceController.php @@ -86,7 +86,7 @@ public function create(Request $request): Response|RedirectResponse public function autofillBrand(AutofillBrandRequest $request, AutofillBrand $autofill): JsonResponse { try { - $metadata = $autofill(data_get($request->validated(), 'url')); + $metadata = $autofill($request->validated('url')); } catch (RuntimeException $e) { return response()->json(['message' => $e->getMessage()], SymfonyResponse::HTTP_UNPROCESSABLE_ENTITY); } diff --git a/tests/Feature/Social/FacebookControllerTest.php b/tests/Feature/Social/FacebookControllerTest.php index 6b01f9c9..0dc6949d 100644 --- a/tests/Feature/Social/FacebookControllerTest.php +++ b/tests/Feature/Social/FacebookControllerTest.php @@ -83,6 +83,50 @@ ]); }); +test('facebook callback shows network_taken when the network is already connected', function () { + config()->set('trypost.self_hosted', false); + + SocialAccount::factory()->create([ + 'workspace_id' => $this->workspace->id, + 'platform' => Platform::Facebook, + 'platform_user_id' => 'existing_page', + ]); + + session(['social_connect_workspace' => $this->workspace->id]); + + $socialiteUser = Mockery::mock(SocialiteUser::class); + $socialiteUser->shouldReceive('getId')->andReturn('facebook_user_123'); + $socialiteUser->token = 'test-user-token'; + + Socialite::shouldReceive('driver') + ->with('facebook') + ->andReturn(Mockery::mock()->shouldReceive('usingGraphVersion')->andReturnSelf()->shouldReceive('user')->andReturn($socialiteUser)->getMock()); + + Http::fake([ + 'https://graph.facebook.com/*/me/accounts*' => Http::response([ + 'data' => [ + [ + 'id' => 'page_123', + 'name' => 'My Facebook Page', + 'username' => 'myfbpage', + 'picture' => ['data' => ['url' => null]], + 'access_token' => 'page-access-token', + ], + ], + ], 200), + ]); + + $response = $this->actingAs($this->user)->get(route('app.social.facebook.callback')); + + $response->assertOk(); + $response->assertViewIs('auth.social-callback'); + $response->assertViewHas('success', false); + $response->assertViewHas('message', __('accounts.popup_callback.network_taken')); + + // The duplicate was blocked by the observer — only the pre-existing account remains. + expect($this->workspace->socialAccounts()->where('platform', Platform::Facebook)->count())->toBe(1); +}); + test('facebook callback redirects to page selection when multiple pages', function () { session([ 'social_connect_workspace' => $this->workspace->id,