From e4bc6f1d5c550a78872f5d460edcca866e85acd0 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 19 May 2026 12:03:41 -0300 Subject: [PATCH] test(auth): cover remaining surfaces of the registration gate - POST /register with ?invite query and no prior session passes the gate. - UserSeeder seeds the admin + workspace on an empty DB and skips when a user already exists. - Login page exposes selfHosted prop in both modes (proves the flag the frontend uses to hide the "Sign up" link reaches the client). --- tests/Feature/Auth/AuthenticationTest.php | 20 +++++++++++++++++ tests/Feature/Auth/RegistrationTest.php | 13 ++++++++++++ tests/Feature/Database/UserSeederTest.php | 26 +++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/Feature/Database/UserSeederTest.php diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 060b1218..8a49a676 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -12,6 +12,26 @@ $response->assertOk(); }); +test('login page exposes selfHosted as false when SELF_HOSTED is off', function () { + config()->set('trypost.self_hosted', false); + + $response = $this->get(route('login')); + + $response->assertOk(); + $page = $response->original->getData()['page']; + expect($page['props']['selfHosted'])->toBeFalse(); +}); + +test('login page exposes selfHosted as true when SELF_HOSTED is on', function () { + config()->set('trypost.self_hosted', true); + + $response = $this->get(route('login')); + + $response->assertOk(); + $page = $response->original->getData()['page']; + expect($page['props']['selfHosted'])->toBeTrue(); +}); + test('users can authenticate using the login screen', function () { $user = User::factory()->create(); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 466a40d2..495791ca 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -168,6 +168,19 @@ expect(User::where('email', 'invitee@example.com')->exists())->toBeTrue(); }); +test('register POST passes when self_hosted with invite query param even without prior session', function () { + config()->set('trypost.self_hosted', true); + + $response = $this->post(route('register.store', ['invite' => 'invite-xyz']), [ + 'name' => 'Invitee', + 'email' => 'invitee@example.com', + 'password' => 'Password123!', + ]); + + $response->assertSessionHasNoErrors(); + expect(User::where('email', 'invitee@example.com')->exists())->toBeTrue(); +}); + test('register works normally when not self_hosted even with pending invite in session', function () { config()->set('trypost.self_hosted', false); diff --git a/tests/Feature/Database/UserSeederTest.php b/tests/Feature/Database/UserSeederTest.php new file mode 100644 index 00000000..b8a98dfa --- /dev/null +++ b/tests/Feature/Database/UserSeederTest.php @@ -0,0 +1,26 @@ +toBe(0); + + $this->seed(UserSeeder::class); + + $admin = User::where('email', 'admin@trypost.it')->first(); + + expect($admin)->not->toBeNull(); + expect($admin->account_id)->not->toBeNull(); + expect($admin->workspaces()->count())->toBe(1); +}); + +test('seeder is idempotent when a user already exists', function () { + User::factory()->create(); + + $this->seed(UserSeeder::class); + + expect(User::where('email', 'admin@trypost.it')->exists())->toBeFalse(); +});