übergang auf pakete, integration von stripe und paypal, blog hinzugefügt.
This commit is contained in:
74
tests/Feature/PurchaseTest.php
Normal file
74
tests/Feature/PurchaseTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Models\User;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\TenantPackage;
|
||||
use App\Models\PackagePurchase;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PurchaseTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_unauthenticated_buy_redirects_to_register()
|
||||
{
|
||||
$package = Package::factory()->create(['price' => 10]);
|
||||
|
||||
$response = $this->get(route('buy.packages', $package->id));
|
||||
|
||||
$response->assertRedirect(route('register', ['package_id' => $package->id]));
|
||||
}
|
||||
|
||||
public function test_unverified_buy_redirects_to_verification()
|
||||
{
|
||||
$package = Package::factory()->create(['price' => 10]);
|
||||
$user = User::factory()->create(['email_verified_at' => null]);
|
||||
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
|
||||
Auth::login($user);
|
||||
|
||||
$response = $this->get(route('buy.packages', $package->id));
|
||||
|
||||
$response->assertRedirect(route('verification.notice'));
|
||||
}
|
||||
|
||||
public function test_free_package_assigns_after_auth()
|
||||
{
|
||||
$freePackage = Package::factory()->create(['price' => 0]);
|
||||
$user = User::factory()->create(['email_verified_at' => now()]);
|
||||
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
|
||||
Auth::login($user);
|
||||
|
||||
$response = $this->get(route('buy.packages', $freePackage->id));
|
||||
|
||||
$response->assertRedirect('/admin');
|
||||
|
||||
$this->assertDatabaseHas('tenant_packages', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $freePackage->id,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('package_purchases', [
|
||||
'user_id' => $user->id,
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $freePackage->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_paid_package_creates_stripe_session()
|
||||
{
|
||||
$paidPackage = Package::factory()->create(['price' => 10]);
|
||||
$user = User::factory()->create(['email_verified_at' => now()]);
|
||||
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
|
||||
Auth::login($user);
|
||||
|
||||
$response = $this->get(route('buy.packages', $paidPackage->id));
|
||||
|
||||
$response->assertStatus(302); // Redirect to Stripe
|
||||
$this->assertStringContainsString('checkout.stripe.com', $response->headers->get('Location'));
|
||||
}
|
||||
}
|
||||
130
tests/Feature/RegistrationTest.php
Normal file
130
tests/Feature/RegistrationTest.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Package;
|
||||
use App\Models\User;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\TenantPackage;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\Welcome;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
|
||||
class RegistrationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_registration_creates_user_and_tenant()
|
||||
{
|
||||
$freePackage = Package::factory()->create(['price' => 0]);
|
||||
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => 'Test User',
|
||||
'username' => 'testuser',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'User',
|
||||
'address' => 'Test Address',
|
||||
'phone' => '123456789',
|
||||
'privacy_consent' => true,
|
||||
'package_id' => $freePackage->id,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('verification.notice'));
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'username' => 'testuser',
|
||||
'email' => 'test@example.com',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'User',
|
||||
'address' => 'Test Address',
|
||||
'phone' => '123456789',
|
||||
]);
|
||||
|
||||
$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,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_without_package()
|
||||
{
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => 'Test User',
|
||||
'username' => 'testuser2',
|
||||
'email' => 'test2@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'User',
|
||||
'address' => 'Test Address',
|
||||
'phone' => '123456789',
|
||||
'privacy_consent' => true,
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('verification.notice'));
|
||||
|
||||
$user = User::where('email', 'test2@example.com')->first();
|
||||
$this->assertNotNull($user->tenant);
|
||||
$this->assertDatabaseMissing('tenant_packages', [
|
||||
'tenant_id' => $user->tenant->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_validation_fails()
|
||||
{
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => '',
|
||||
'username' => '',
|
||||
'email' => 'invalid',
|
||||
'password' => 'short',
|
||||
'password_confirmation' => 'different',
|
||||
'first_name' => '',
|
||||
'last_name' => '',
|
||||
'address' => '',
|
||||
'phone' => '',
|
||||
'privacy_consent' => false,
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors([
|
||||
'name', 'username', 'email', 'password', 'first_name', 'last_name', 'address', 'phone', 'privacy_consent',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registered_event_sends_welcome_email()
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$freePackage = Package::factory()->create(['price' => 0]);
|
||||
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => 'Test User',
|
||||
'username' => 'testuser3',
|
||||
'email' => 'test3@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'first_name' => 'Test',
|
||||
'last_name' => 'User',
|
||||
'address' => 'Test Address',
|
||||
'phone' => '123456789',
|
||||
'privacy_consent' => true,
|
||||
'package_id' => $freePackage->id,
|
||||
]);
|
||||
|
||||
Mail::assertQueued(Welcome::class, function ($mail) {
|
||||
return $mail->to[0]['address'] === 'test3@example.com';
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user