Marketing: route registration to checkout

This commit is contained in:
Codex Agent
2026-01-06 08:36:55 +01:00
parent 34eb2b94b3
commit f89f6d6223
14 changed files with 105 additions and 328 deletions

View File

@@ -3,10 +3,7 @@
namespace Tests\Feature;
use App\Mail\Welcome;
use App\Models\Package;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
@@ -14,18 +11,18 @@ class RegistrationTest extends TestCase
{
use RefreshDatabase;
private function captureLocation($response): string
private function assertRedirectsToPackages($response, ?int $packageId = null): void
{
$redirect = $response->headers->get('Location');
$location = $redirect ?? $response->headers->get('X-Inertia-Location');
$params = array_filter([
'locale' => 'de',
'package_id' => $packageId,
]);
return $location ?? '';
$response->assertRedirect(route('packages', $params));
}
public function test_registration_creates_user_and_tenant(): void
{
$freePackage = Package::factory()->create(['price' => 0]);
$response = $this->post(route('register.store'), [
'username' => 'testuser',
'email' => 'test@example.com',
@@ -36,35 +33,12 @@ class RegistrationTest extends TestCase
'address' => 'Test Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $freePackage->id,
]);
$location = $this->captureLocation($response);
$expected = route('verification.notice', absolute: false);
$this->assertNotEmpty($location);
$this->assertTrue($location === $expected || Str::endsWith($location, $expected));
$this->assertDatabaseHas('users', [
'username' => 'testuser',
$this->assertGuest();
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', [
'email' => 'test@example.com',
'first_name' => 'Test',
'last_name' => 'User',
'address' => 'Test Address',
'phone' => '123456789',
'role' => 'tenant_admin',
]);
$user = User::where('email', 'test@example.com')->first();
$this->assertNotNull($user->tenant);
$this->assertDatabaseHas('tenants', [
'user_id' => $user->id,
'name' => 'Test User',
]);
$this->assertDatabaseHas('tenant_packages', [
'tenant_id' => $user->tenant->id,
'package_id' => $freePackage->id,
]);
}
@@ -82,21 +56,10 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$location = $this->captureLocation($response);
$expected = route('verification.notice', absolute: false);
$this->assertNotEmpty($location);
$this->assertTrue($location === $expected || Str::endsWith($location, $expected));
$user = User::where('email', 'test2@example.com')->first();
$this->assertNotNull($user->tenant);
$this->assertDatabaseHas('users', [
$this->assertGuest();
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', [
'email' => 'test2@example.com',
'role' => 'user',
]);
$this->assertDatabaseMissing('tenant_packages', [
'tenant_id' => $user->tenant->id,
]);
}
@@ -114,14 +77,15 @@ class RegistrationTest extends TestCase
'privacy_consent' => false,
]);
$response->assertSessionHasErrors([
'username', 'email', 'password', 'first_name', 'last_name', 'address', 'phone', 'privacy_consent',
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', [
'email' => 'invalid',
]);
}
public function test_registration_with_paid_package_redirects_to_checkout_flow(): void
{
$paidPackage = Package::factory()->create(['price' => 10.00]);
$paidPackageId = 789;
$response = $this->post(route('register.store'), [
'username' => 'paiduser',
@@ -133,18 +97,13 @@ class RegistrationTest extends TestCase
'address' => 'Paid Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $paidPackage->id,
'package_id' => $paidPackageId,
]);
$response->assertRedirect(route('buy.packages', [
'locale' => 'de',
'packageId' => $paidPackage->id,
]));
$this->assertDatabaseHas('users', [
'username' => 'paiduser',
$this->assertGuest();
$this->assertRedirectsToPackages($response, $paidPackageId);
$this->assertDatabaseMissing('users', [
'email' => 'paid@example.com',
'role' => 'user',
]);
}
@@ -152,8 +111,6 @@ class RegistrationTest extends TestCase
{
Mail::fake();
$freePackage = Package::factory()->create(['price' => 0]);
$this->post(route('register.store'), [
'username' => 'testuser3',
'email' => 'test3@example.com',
@@ -164,11 +121,8 @@ class RegistrationTest extends TestCase
'address' => 'Test Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $freePackage->id,
]);
Mail::assertSent(Welcome::class, function ($mail) {
return $mail->hasTo('test3@example.com');
});
Mail::assertNotSent(Welcome::class);
}
}