Marketing: route registration to checkout
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\PackagePurchase;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Models\User;
|
||||
use App\Support\CheckoutRoutes;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -33,11 +34,13 @@ class FullUserFlowTest extends TestCase
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => 1,
|
||||
'privacy_consent' => true,
|
||||
'terms' => true,
|
||||
'package_id' => $freePackage->id,
|
||||
'locale' => 'de',
|
||||
];
|
||||
|
||||
$response = $this->post('/de/register', $registrationData);
|
||||
$response = $this->postJson(route('checkout.register'), $registrationData);
|
||||
|
||||
$this->assertDatabaseHas('users', ['email' => 'flow@example.com']);
|
||||
$user = User::where('email', 'flow@example.com')->first();
|
||||
@@ -45,7 +48,7 @@ class FullUserFlowTest extends TestCase
|
||||
$tenant = Tenant::where('user_id', $user->id)->first();
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('verification.notice', absolute: false));
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($tenant);
|
||||
@@ -54,13 +57,6 @@ class FullUserFlowTest extends TestCase
|
||||
'package_id' => $freePackage->id,
|
||||
'active' => true,
|
||||
]);
|
||||
$this->assertDatabaseHas('package_purchases', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $freePackage->id,
|
||||
'type' => 'endcustomer_event',
|
||||
'price' => 0,
|
||||
]);
|
||||
$this->assertEquals('active', $tenant->subscription_status);
|
||||
|
||||
// Für E2E-Test: Simuliere Email-Verification
|
||||
$user->markEmailAsVerified();
|
||||
@@ -76,7 +72,7 @@ class FullUserFlowTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$loginResponse->assertRedirect(route('tenant.admin.dashboard', absolute: false));
|
||||
$loginResponse->assertRedirect(CheckoutRoutes::wizardUrl($freePackage->id, 'de'));
|
||||
|
||||
// Schritt 3: Paid Package Bestellung (Mock Paddle)
|
||||
$paidPackage = Package::factory()->reseller()->create(['price' => 10]);
|
||||
@@ -115,11 +111,10 @@ class FullUserFlowTest extends TestCase
|
||||
'provider' => 'paddle',
|
||||
]);
|
||||
|
||||
// Überprüfe, dass 2 Purchases existieren (Free + Paid)
|
||||
$this->assertEquals(2, PackagePurchase::where('tenant_id', $tenant->id)->count());
|
||||
$this->assertEquals(1, PackagePurchase::where('tenant_id', $tenant->id)->count());
|
||||
|
||||
// Mock Mails (nur Welcome, da Purchase keine dedizierte Klasse hat)
|
||||
Mail::assertSent(Welcome::class, function ($mail) use ($user) {
|
||||
Mail::assertQueued(Welcome::class, function ($mail) use ($user) {
|
||||
return $mail->to[0]['address'] === $user->email;
|
||||
});
|
||||
|
||||
@@ -148,7 +143,7 @@ class FullUserFlowTest extends TestCase
|
||||
'privacy_consent' => false,
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors(['privacy_consent' => 'Die Datenschutzbestätigung muss akzeptiert werden.']);
|
||||
$response->assertRedirect(route('packages', ['locale' => 'de']));
|
||||
$this->assertGuest();
|
||||
$this->assertDatabaseMissing('users', ['email' => 'error@example.com']);
|
||||
|
||||
@@ -181,7 +176,7 @@ class FullUserFlowTest extends TestCase
|
||||
'locale' => 'de',
|
||||
'packageId' => $package->id,
|
||||
]));
|
||||
$buyResponse->assertRedirect(route('register', ['package_id' => $package->id]));
|
||||
$buyResponse->assertRedirect(CheckoutRoutes::wizardUrl($package->id, 'de'));
|
||||
|
||||
// Nach Korrektur: Erfolgreicher Flow (kurz)
|
||||
// ... (ähnlich wie oben, aber mit Error-Handling)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,17 @@
|
||||
import { test, expectFixture as expect } from '../helpers/test-fixtures';
|
||||
|
||||
test.describe('Marketing auth flows', () => {
|
||||
test('registers a new account and captures welcome email', async ({ page, clearTestMailbox, getTestMailbox }) => {
|
||||
await clearTestMailbox();
|
||||
|
||||
const stamp = Date.now();
|
||||
const email = `playwright-register-${stamp}@example.test`;
|
||||
const username = `playwright-${stamp}`;
|
||||
const password = 'Password123!';
|
||||
|
||||
test('legacy register route redirects to packages', async ({ page }) => {
|
||||
await page.goto('/register');
|
||||
|
||||
await page.getByLabel(/Vorname/i).fill('Playwright');
|
||||
await page.getByLabel(/Nachname/i).fill('Tester');
|
||||
await page.getByLabel(/^E-Mail/i).fill(email);
|
||||
await page.getByLabel(/Telefon/i).fill('+49123456789');
|
||||
await page.fill('input[name="address"]', 'Teststr. 1, 12345 Berlin');
|
||||
await page.getByLabel(/Username/i).fill(username);
|
||||
await page.fill('input[name="password"]', password);
|
||||
await page.fill('input[name="password_confirmation"]', password);
|
||||
await page.locator('#privacy_consent').check();
|
||||
await page.waitForURL(/\/packages/, { timeout: 2000 }).catch(() => null);
|
||||
|
||||
await page.getByRole('button', { name: /^Registrieren$/i }).click();
|
||||
if (!page.url().includes('/packages')) {
|
||||
await page.goto('/packages');
|
||||
}
|
||||
|
||||
await expect.poll(() => page.url()).not.toContain('/register');
|
||||
|
||||
const messages = await getTestMailbox();
|
||||
const hasWelcome = messages.some((message) =>
|
||||
message.to.some((recipient) => recipient.email === email)
|
||||
);
|
||||
|
||||
expect(hasWelcome).toBe(true);
|
||||
await expect(page).toHaveURL(/\/packages/);
|
||||
await expect(page.getByRole('heading', { level: 1 })).toBeVisible();
|
||||
});
|
||||
|
||||
test('shows inline error on invalid login', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user