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).
This commit is contained in:
parent
74bd88d3d6
commit
e4bc6f1d5c
3 changed files with 59 additions and 0 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
26
tests/Feature/Database/UserSeederTest.php
Normal file
26
tests/Feature/Database/UserSeederTest.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Seeders\UserSeeder;
|
||||
|
||||
test('seeder creates the admin user and a workspace when database is empty', function () {
|
||||
expect(User::count())->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();
|
||||
});
|
||||
Loading…
Reference in a new issue