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:
56
tests/Feature/Tenant/TenantTestCase.php
Normal file
56
tests/Feature/Tenant/TenantTestCase.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Tests\TestCase;
|
||||
|
||||
abstract class TenantTestCase extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected Tenant $tenant;
|
||||
protected User $tenantUser;
|
||||
protected string $token;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->tenant = Tenant::factory()->create([
|
||||
'name' => 'Test Tenant',
|
||||
'slug' => 'test-tenant',
|
||||
]);
|
||||
|
||||
$this->tenantUser = User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'tenant_id' => $this->tenant->id,
|
||||
'role' => 'admin',
|
||||
]);
|
||||
|
||||
$this->token = 'mock-jwt-token-' . $this->tenant->id . '-' . time();
|
||||
}
|
||||
|
||||
protected function authenticatedRequest($method, $uri, array $data = [], array $headers = [])
|
||||
{
|
||||
$headers['Authorization'] = 'Bearer ' . $this->token;
|
||||
|
||||
// Temporarily override the middleware to skip auth and set tenant
|
||||
$this->app['router']->pushMiddlewareToGroup('api', MockTenantMiddleware::class, 'mock-tenant');
|
||||
|
||||
return $this->withHeaders($headers)->json($method, $uri, $data);
|
||||
}
|
||||
|
||||
protected function mockTenantContext()
|
||||
{
|
||||
$this->actingAs($this->tenantUser);
|
||||
|
||||
// Set tenant globally for tests
|
||||
$this->app->instance('tenant', $this->tenant);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user