feat: Implementierung des Checkout-Logins mit E-Mail/Username-Support
This commit is contained in:
@@ -13,34 +13,48 @@ class CheckoutAuthTest extends TestCase
|
||||
|
||||
public function test_checkout_login_returns_json_response_with_valid_credentials()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()->create(['pending_purchase' => false]);
|
||||
$package = Package::factory()->create();
|
||||
|
||||
$this->actingAs($user); // To simulate session, but for login test, guest
|
||||
|
||||
$response = $this->postJson(route('checkout.login'), [
|
||||
'login' => $user->email,
|
||||
'identifier' => $user->email,
|
||||
'password' => 'password',
|
||||
'remember' => false,
|
||||
'locale' => 'de',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'user' => [
|
||||
'id',
|
||||
'email',
|
||||
'name',
|
||||
'pending_purchase',
|
||||
],
|
||||
'message',
|
||||
])
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
'message' => 'Login erfolgreich',
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'pending_purchase' => false,
|
||||
'pending_purchase' => true, // Set by logic
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertAuthenticatedAs($user);
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'pending_purchase' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_checkout_login_returns_validation_errors_with_invalid_credentials()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->postJson(route('checkout.login'), [
|
||||
'login' => $user->email,
|
||||
'identifier' => 'invalid@example.com',
|
||||
'password' => 'wrong-password',
|
||||
'remember' => false,
|
||||
'locale' => 'de',
|
||||
@@ -49,35 +63,49 @@ class CheckoutAuthTest extends TestCase
|
||||
$response->assertStatus(422)
|
||||
->assertJsonStructure([
|
||||
'errors' => [
|
||||
'login' => [],
|
||||
'identifier' => [],
|
||||
],
|
||||
]);
|
||||
])
|
||||
->assertJsonPath('errors.identifier.0', 'Ungültige Anmeldedaten.');
|
||||
|
||||
$this->assertGuest();
|
||||
}
|
||||
|
||||
public function test_checkout_login_with_username()
|
||||
{
|
||||
$user = User::factory()->create(['username' => 'testuser']);
|
||||
$user = User::factory()->create(['username' => 'testuser', 'pending_purchase' => false]);
|
||||
|
||||
$response = $this->postJson(route('checkout.login'), [
|
||||
'login' => 'testuser', // Using username as login field
|
||||
'identifier' => 'testuser',
|
||||
'password' => 'password',
|
||||
'remember' => false,
|
||||
'locale' => 'de',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonStructure([
|
||||
'user' => [
|
||||
'id',
|
||||
'email',
|
||||
'name',
|
||||
'pending_purchase',
|
||||
],
|
||||
'message',
|
||||
])
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
'message' => 'Login erfolgreich',
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'pending_purchase' => false,
|
||||
'username' => 'testuser',
|
||||
'pending_purchase' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertAuthenticatedAs($user);
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'pending_purchase' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_checkout_register_creates_user_and_tenant_successfully()
|
||||
|
||||
Reference in New Issue
Block a user