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

@@ -2,36 +2,29 @@
namespace Tests\Feature\Auth;
use App\Models\Package;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
private function assertRedirectsToVerification($response): void
private function assertRedirectsToPackages($response, ?int $packageId = null): void
{
$expected = route('verification.notice', absolute: false);
$target = $response->headers->get('Location')
?? $response->headers->get('X-Inertia-Location');
$params = array_filter([
'locale' => 'de',
'package_id' => $packageId,
]);
$this->assertNotNull($target, 'Registration response did not include a redirect target.');
$this->assertTrue(
$target === $expected || Str::endsWith($target, $expected),
'Registration should redirect or instruct Inertia to navigate to the verification notice.'
);
$response->assertRedirect(route('packages', $params));
}
public function test_registration_screen_can_be_rendered(): void
{
$response = $this->get(route('register'));
$response->assertStatus(200);
$this->assertRedirectsToPackages($response);
}
public function test_new_users_can_register(): void
@@ -49,18 +42,14 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$this->assertAuthenticated();
$this->assertRedirectsToVerification($response);
$this->assertDatabaseHas('users', ['email' => 'test@example.com']);
$this->assertDatabaseHas('tenants', [
'user_id' => User::latest()->first()->id,
'contact_email' => 'test@example.com',
]);
$this->assertGuest();
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', ['email' => 'test@example.com']);
}
public function test_registration_with_free_package_assigns_tenant_package(): void
{
$freePackage = Package::factory()->endcustomer()->create(['price' => 0]);
$freePackageId = 123;
$response = $this->post(route('register.store'), [
'name' => 'Test User',
@@ -73,35 +62,17 @@ class RegistrationTest extends TestCase
'address' => 'Musterstr. 1',
'phone' => '+49123456789',
'privacy_consent' => true,
'package_id' => $freePackage->id,
'package_id' => $freePackageId,
]);
$this->assertAuthenticated();
$this->assertRedirectsToVerification($response);
$user = User::latest()->first();
$tenant = Tenant::where('user_id', $user->id)->first();
$this->assertDatabaseHas('tenant_packages', [
'tenant_id' => $tenant->id,
'package_id' => $freePackage->id,
'active' => true,
'price' => 0,
]);
$this->assertDatabaseHas('package_purchases', [
'tenant_id' => $tenant->id,
'package_id' => $freePackage->id,
'type' => 'endcustomer_event',
'price' => 0,
]);
$this->assertEquals('active', $tenant->subscription_status);
$this->assertGuest();
$this->assertRedirectsToPackages($response, $freePackageId);
$this->assertDatabaseMissing('users', ['email' => 'free@example.com']);
}
public function test_registration_with_paid_package_redirects_to_buy(): void
{
$paidPackage = Package::factory()->endcustomer()->create(['price' => 10]);
$paidPackageId = 456;
$response = $this->post(route('register.store'), [
'name' => 'Test User',
@@ -114,15 +85,12 @@ class RegistrationTest extends TestCase
'address' => 'Musterstr. 1',
'phone' => '+49123456789',
'privacy_consent' => true,
'package_id' => $paidPackage->id,
'package_id' => $paidPackageId,
]);
$response->assertRedirect(route('buy.packages', [
'locale' => 'de',
'packageId' => $paidPackage->id,
]));
$this->assertDatabaseHas('users', ['email' => 'paid@example.com']);
$this->assertDatabaseMissing('tenant_packages', ['package_id' => $paidPackage->id]);
$this->assertGuest();
$this->assertRedirectsToPackages($response, $paidPackageId);
$this->assertDatabaseMissing('users', ['email' => 'paid@example.com']);
}
public function test_registration_fails_with_invalid_email(): void
@@ -140,8 +108,7 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$response->assertStatus(302);
$response->assertSessionHasErrors(['email']);
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', ['email' => 'invalid-email']);
}
@@ -160,8 +127,8 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$this->assertAuthenticated();
$this->assertRedirectsToVerification($response);
$this->assertGuest();
$this->assertRedirectsToPackages($response);
}
public function test_registration_fails_with_short_password(): void
@@ -179,8 +146,7 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$response->assertStatus(302);
$response->assertSessionHasErrors(['password']);
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', ['email' => 'short@example.com']);
}
@@ -199,8 +165,7 @@ class RegistrationTest extends TestCase
'privacy_consent' => false,
]);
$response->assertStatus(302);
$response->assertSessionHasErrors(['privacy_consent']);
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', ['email' => 'noconsent@example.com']);
}
@@ -221,8 +186,7 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$response->assertStatus(302);
$response->assertSessionHasErrors(['email']);
$this->assertRedirectsToPackages($response);
}
public function test_registration_fails_with_mismatched_passwords(): void
@@ -240,8 +204,7 @@ class RegistrationTest extends TestCase
'privacy_consent' => true,
]);
$response->assertStatus(302);
$response->assertSessionHasErrors(['password']);
$this->assertRedirectsToPackages($response);
$this->assertDatabaseMissing('users', ['email' => 'mismatch@example.com']);
}
@@ -261,8 +224,7 @@ class RegistrationTest extends TestCase
'package_id' => 999,
]);
$response->assertStatus(302);
$response->assertSessionHasErrors(['package_id']);
$this->assertRedirectsToPackages($response, 999);
$this->assertDatabaseMissing('users', ['email' => 'invalidpkg@example.com']);
}
}