test: cover network_taken popup on OAuth conflict; use FormRequest accessor

- Add a controller-level test asserting the Facebook OAuth callback returns the
  localized network_taken popup (not a generic error) when the network is
  already connected — covers the bug-A fix across the OAuth callbacks.
- WorkspaceController::autofillBrand: use $request->validated('url') instead of
  data_get on the validated array (idiomatic FormRequest accessor).
This commit is contained in:
Paulo Castellano 2026-06-22 08:01:08 -03:00
parent 0619f2a0f4
commit 17449bfe2a
2 changed files with 45 additions and 1 deletions

View file

@ -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);
}

View file

@ -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,