trypost/tests/Feature/GitHubAuthToggleTest.php
Paulo Castellano 2e9e0f716b feat: capture signup UTMs/IP and add GitHub OAuth login
Persists marketing attribution and registration metadata for new users
across the three signup paths (email, Google, GitHub):

- 5 utm_* columns + registration_ip on the users table
- PreservesUtmParameters trait stores incoming utm_* query params on
  the register/redirect GET, retrieves them on the POST/callback —
  surviving the OAuth round-trip via session
- request()->ip() captured at the controller layer

Adds GitHub as a second OAuth provider:

- GitHubController mirroring the Google one (now renamed from
  SocialLoginController for symmetry)
- Settings → Authentication can connect/disconnect GitHub like Google
- Single SocialLogin.vue component replaces the per-provider buttons
  on Login/Register, rendering each enabled provider plus a single
  "or continue with" divider

UserFactory gains defaults for the new nullable columns so model
strict-mode access in tests doesn't trip.
2026-05-04 18:42:25 -03:00

54 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
test('login page shares github auth enabled prop as false when disabled', function () {
config(['trypost.github_auth_enabled' => false]);
$response = $this->get(route('login'));
$response->assertOk();
$page = $response->original->getData()['page'];
expect($page['props']['githubAuthEnabled'])->toBeFalse();
});
test('login page shares github auth enabled prop as true when enabled', function () {
config(['trypost.github_auth_enabled' => true]);
$response = $this->get(route('login'));
$response->assertOk();
$page = $response->original->getData()['page'];
expect($page['props']['githubAuthEnabled'])->toBeTrue();
});
test('register page shares github auth enabled prop', function () {
config(['trypost.github_auth_enabled' => true]);
$response = $this->get(route('register'));
$response->assertOk();
$page = $response->original->getData()['page'];
expect($page['props']['githubAuthEnabled'])->toBeTrue();
});
test('github auth redirect route exists', function () {
config(['services.github.client_id' => 'test-id']);
config(['services.github.client_secret' => 'test-secret']);
config(['services.github.redirect' => 'https://app.trypost.test/auth/github/callback']);
$response = $this->get(route('auth.github.redirect'));
// Should redirect to GitHub OAuth, not 404
$response->assertRedirect();
});
test('github auth callback route exists', function () {
$response = $this->get(route('auth.github.callback'));
// Should redirect to login on failure (no OAuth code), not 404
$response->assertRedirect(route('login'));
});