Fix endcustomer package allocation and event create gating
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-02-06 13:21:11 +01:00
parent 0291d537fb
commit df00deb0df
11 changed files with 409 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ use App\Models\Tenant;
use App\Models\User;
use App\Services\Checkout\CheckoutSessionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@@ -19,6 +20,10 @@ class CheckoutSessionLocalConfirmationTest extends TestCase
public function test_local_confirmation_marks_checkout_completed(): void
{
$this->app['env'] = 'local';
Config::set('checkout.providers', [
CheckoutSession::PROVIDER_LEMONSQUEEZY,
CheckoutSession::PROVIDER_FREE,
]);
Mail::fake();
Notification::fake();
@@ -70,4 +75,61 @@ class CheckoutSessionLocalConfirmationTest extends TestCase
'active' => true,
]);
}
public function test_local_confirmation_creates_new_endcustomer_tenant_package_per_purchase(): void
{
$this->app['env'] = 'local';
Config::set('checkout.providers', [
CheckoutSession::PROVIDER_LEMONSQUEEZY,
CheckoutSession::PROVIDER_FREE,
]);
Mail::fake();
Notification::fake();
$tenant = Tenant::factory()->create();
$user = User::factory()->for($tenant)->create();
$package = Package::factory()->create([
'type' => 'endcustomer',
'lemonsqueezy_variant_id' => 'pri_456',
'lemonsqueezy_product_id' => 'pro_456',
'price' => 120,
]);
$sessions = app(CheckoutSessionService::class);
$firstSession = $sessions->createOrResume($user, $package, ['tenant' => $tenant]);
$sessions->selectProvider($firstSession, CheckoutSession::PROVIDER_LEMONSQUEEZY);
$this->actingAs($user);
$this->withSession(['_token' => 'test-token']);
$this->postJson(
route('checkout.session.confirm', $firstSession),
[
'order_id' => 'ord_456_a',
'checkout_id' => 'chk_456_a',
],
['X-CSRF-TOKEN' => 'test-token']
)->assertOk();
$secondSession = $sessions->createOrResume($user, $package, ['tenant' => $tenant]);
$sessions->selectProvider($secondSession, CheckoutSession::PROVIDER_LEMONSQUEEZY);
$this->postJson(
route('checkout.session.confirm', $secondSession),
[
'order_id' => 'ord_456_b',
'checkout_id' => 'chk_456_b',
],
['X-CSRF-TOKEN' => 'test-token']
)->assertOk();
$this->assertSame(
2,
\App\Models\TenantPackage::query()
->where('tenant_id', $tenant->id)
->where('package_id', $package->id)
->count()
);
}
}