Harden credit flows and add RevenueCat webhook
This commit is contained in:
46
tests/Feature/Tenant/EventCreditsTest.php
Normal file
46
tests/Feature/Tenant/EventCreditsTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Models\EventType;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class EventCreditsTest extends TenantTestCase
|
||||
{
|
||||
public function test_event_creation_requires_credits(): void
|
||||
{
|
||||
$this->tenant->update(['event_credits_balance' => 0]);
|
||||
$eventType = EventType::factory()->create();
|
||||
|
||||
$payload = [
|
||||
'name' => 'Sample Event',
|
||||
'description' => 'Test description',
|
||||
'event_date' => Carbon::now()->addDays(3)->toDateString(),
|
||||
'event_type_id' => $eventType->id,
|
||||
];
|
||||
|
||||
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/events', $payload);
|
||||
|
||||
$response->assertStatus(402)
|
||||
->assertJson([
|
||||
'error' => 'Insufficient event credits. Please purchase more credits.',
|
||||
]);
|
||||
|
||||
$this->tenant->update(['event_credits_balance' => 2]);
|
||||
|
||||
$createResponse = $this->authenticatedRequest('POST', '/api/v1/tenant/events', $payload);
|
||||
|
||||
$createResponse->assertStatus(201)
|
||||
->assertJsonPath('message', 'Event created successfully')
|
||||
->assertJsonPath('balance', 1);
|
||||
|
||||
$this->tenant->refresh();
|
||||
$this->assertSame(1, $this->tenant->event_credits_balance);
|
||||
|
||||
$this->assertDatabaseHas('event_credits_ledger', [
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'delta' => -1,
|
||||
'reason' => 'event_create',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user