ü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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user