change role to "user" for new registrations, fixed some registration form errors and implemented a reg-test

This commit is contained in:
Codex Agent
2025-10-02 15:06:50 +02:00
parent 7475210893
commit 1845d83583
13 changed files with 416 additions and 191 deletions

View File

@@ -34,7 +34,7 @@ class RegistrationTest extends TestCase
'package_id' => $freePackage->id,
]);
$response->assertRedirect(route('verification.notice'));
$response->assertRedirect(route('verification.notice', absolute: false));
$this->assertDatabaseHas('users', [
'username' => 'testuser',
@@ -43,6 +43,7 @@ class RegistrationTest extends TestCase
'last_name' => 'User',
'address' => 'Test Address',
'phone' => '123456789',
'role' => 'tenant_admin',
]);
$user = User::where('email', 'test@example.com')->first();
@@ -72,10 +73,14 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$response->assertRedirect(route('verification.notice'));
$response->assertRedirect(route('verification.notice', absolute: false));
$user = User::where('email', 'test2@example.com')->first();
$this->assertNotNull($user->tenant);
$this->assertDatabaseHas('users', [
'email' => 'test2@example.com',
'role' => 'user',
]);
$this->assertDatabaseMissing('tenant_packages', [
'tenant_id' => $user->tenant->id,
]);
@@ -100,6 +105,32 @@ class RegistrationTest extends TestCase
]);
}
public function test_registration_with_paid_package_returns_inertia_redirect()
{
$paidPackage = Package::factory()->create(['price' => 10.00]);
$response = $this->post(route('register.store'), [
'username' => 'paiduser',
'email' => 'paid@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'first_name' => 'Paid',
'last_name' => 'User',
'address' => 'Paid Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $paidPackage->id,
]);
$response->assertRedirect(route('buy.packages', $paidPackage->id));
$this->assertDatabaseHas('users', [
'username' => 'paiduser',
'email' => 'paid@example.com',
'role' => 'user', // No upgrade for paid until payment
]);
}
public function test_registered_event_sends_welcome_email()
{
Mail::fake();
@@ -123,4 +154,4 @@ class RegistrationTest extends TestCase
return $mail->to[0]['address'] === 'test3@example.com';
});
}
}
}