Updated invitation flow, Moved jetstream function to REST endpoints; Lower case email

This commit is contained in:
Constantin Graf
2026-02-25 17:28:34 +01:00
committed by Constantin Graf
parent d732064f31
commit a30d192ea2
37 changed files with 942 additions and 209 deletions

View File

@@ -8,21 +8,21 @@ use App\Enums\Role;
use App\Enums\Weekday;
use App\Events\NewsletterRegistered;
use App\Models\Member;
use App\Models\OrganizationInvitation;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use App\Service\IpLookup\IpLookupResponseDto;
use App\Service\IpLookup\IpLookupServiceContract;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Jetstream;
use Tests\TestCase;
use Tests\TestCaseWithDatabase;
use TiMacDonald\Log\LogEntry;
class RegistrationTest extends TestCase
class RegistrationTest extends TestCaseWithDatabase
{
use RefreshDatabase;
public function test_registration_screen_can_be_rendered(): void
{
if (! Features::enabled(Features::registration())) {
@@ -346,4 +346,82 @@ class RegistrationTest extends TestCase
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
}
public function test_registration_does_not_create_private_organization_if_invite_was_accepted_for_the_email_with_the_registration_email(): void
{
// Arrange
$user = $this->createUserWithPermission();
$organizationInvitation = OrganizationInvitation::factory()
->forOrganization($user->organization)
->role(Role::Employee)
->accepted()
->create([
'email' => 'test@example.com',
]);
// Act
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
$newUser = User::where('email', 'test@example.com')->first();
$this->assertNotNull($newUser);
$this->assertDatabaseMissing(OrganizationInvitation::class, [
'email' => 'test@example.com',
]);
$organizations = $newUser->organizations;
$this->assertCount(1, $organizations);
$this->assertSame($user->organization->id, $organizations->first()->id);
}
public function test_registration_logs_and_skips_accepted_invitation_with_invalid_role(): void
{
// Arrange
$user = $this->createUserWithPermission();
$organizationInvitation = OrganizationInvitation::factory()
->forOrganization($user->organization)
->accepted()
->create([
'email' => 'test@example.com',
'role' => 'invalid-role',
]);
// Act
$response = $this->post('/register', [
'name' => 'Test User',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature(),
]);
// Assert
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
Log::assertLogged(fn (LogEntry $log) => $log->level === 'error'
&& $log->message === 'Invalid role in invitation'
&& $log->context === [
'invitation' => $organizationInvitation->getKey(),
'role' => 'invalid-role',
]);
$newUser = User::where('email', 'test@example.com')->firstOrFail();
$this->assertDatabaseHas(OrganizationInvitation::class, [
'id' => $organizationInvitation->getKey(),
'email' => 'test@example.com',
'role' => 'invalid-role',
]);
$this->assertDatabaseMissing(Member::class, [
'organization_id' => $user->organization->getKey(),
'user_id' => $newUser->getKey(),
]);
$organizations = $newUser->organizations;
$this->assertCount(1, $organizations);
$this->assertNotSame($user->organization->id, $organizations->first()->id);
}
}