Implement multi-tenancy support with OAuth2 authentication for tenant admins, Stripe integration for event purchases and credits ledger, new Filament resources for event purchases, updated API routes and middleware for tenant isolation and token guarding, added factories/seeders/migrations for new models (Tenant, EventPurchase, OAuth entities, etc.), enhanced tests, and documentation updates. Removed outdated DemoAchievementsSeeder.

This commit is contained in:
2025-09-17 19:56:54 +02:00
parent 5fbb9cb240
commit 42d6e98dff
84 changed files with 6125 additions and 155 deletions

View File

@@ -0,0 +1,132 @@
<?php
namespace Tests\Unit;
use App\Models\Event;
use App\Models\Photo;
use App\Models\PurchaseHistory;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TenantModelTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function tenant_has_many_events()
{
$tenant = Tenant::factory()->create();
Event::factory(3)->create(['tenant_id' => $tenant->id]);
$this->assertCount(3, $tenant->events);
}
/** @test */
public function tenant_has_photos_through_events()
{
$tenant = Tenant::factory()->create();
$event = Event::factory()->create(['tenant_id' => $tenant->id]);
Photo::factory(2)->create(['event_id' => $event->id]);
$this->assertCount(2, $tenant->photos);
}
/** @test */
public function tenant_has_many_purchases()
{
$tenant = Tenant::factory()->create();
PurchaseHistory::factory(2)->create(['tenant_id' => $tenant->id]);
$this->assertCount(2, $tenant->purchases);
}
/** @test */
public function active_subscription_returns_true_if_not_expired()
{
$tenant = Tenant::factory()->create([
'subscription_tier' => 'pro',
'subscription_expires_at' => now()->addDays(30),
]);
$this->assertTrue($tenant->active_subscription);
}
/** @test */
public function active_subscription_returns_false_if_expired()
{
$tenant = Tenant::factory()->create([
'subscription_tier' => 'pro',
'subscription_expires_at' => now()->subDays(1),
]);
$this->assertFalse($tenant->active_subscription);
}
/** @test */
public function active_subscription_returns_false_if_no_subscription()
{
$tenant = Tenant::factory()->create([
'subscription_tier' => 'free',
'subscription_expires_at' => null,
]);
$this->assertFalse($tenant->active_subscription);
}
/** @test */
public function can_decrement_credits()
{
$tenant = Tenant::factory()->create(['event_credits_balance' => 10]);
$result = $tenant->decrementCredits(3);
$this->assertTrue($result);
$this->assertEquals(7, $tenant->fresh()->event_credits_balance);
}
/** @test */
public function can_increment_credits()
{
$tenant = Tenant::factory()->create(['event_credits_balance' => 10]);
$result = $tenant->incrementCredits(5);
$this->assertTrue($result);
$this->assertEquals(15, $tenant->fresh()->event_credits_balance);
}
/** @test */
public function decrementing_credits_does_not_go_negative()
{
$tenant = Tenant::factory()->create(['event_credits_balance' => 2]);
$result = $tenant->decrementCredits(5);
$this->assertFalse($result);
$this->assertEquals(2, $tenant->fresh()->event_credits_balance);
}
/** @test */
public function settings_are_properly_cast_as_json()
{
$tenant = Tenant::factory()->create([
'settings' => json_encode(['theme' => 'dark', 'logo' => 'logo.png'])
]);
$this->assertIsArray($tenant->settings);
$this->assertEquals('dark', $tenant->settings['theme']);
}
/** @test */
public function features_are_cast_as_array()
{
$tenant = Tenant::factory()->create([
'features' => ['photo_likes' => true, 'analytics' => false]
]);
$this->assertIsArray($tenant->features);
$this->assertTrue($tenant->features['photo_likes']);
$this->assertFalse($tenant->features['analytics']);
}
}