## Summary - move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling - update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location - add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation` - integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404` ## Remaining Rollout Checks - validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout - confirm web, queue, and scheduler processes all start from the expected working directory in staging/production - verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #213
133 lines
3.4 KiB
PHP
133 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
function restoreIntuneTenantId(string|false $original): void
|
|
{
|
|
$original !== false
|
|
? putenv("INTUNE_TENANT_ID={$original}")
|
|
: putenv('INTUNE_TENANT_ID');
|
|
}
|
|
|
|
it('returns env-configured tenant when active', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=tenant-env');
|
|
|
|
$preferred = Tenant::create([
|
|
'tenant_id' => 'tenant-env',
|
|
'name' => 'Preferred Tenant',
|
|
'is_current' => false,
|
|
]);
|
|
|
|
Tenant::create([
|
|
'tenant_id' => 'other-tenant',
|
|
'name' => 'Other Tenant',
|
|
'is_current' => true,
|
|
]);
|
|
|
|
$resolved = Tenant::current();
|
|
|
|
expect($resolved->id)->toBe($preferred->id);
|
|
|
|
restoreIntuneTenantId($originalEnv);
|
|
});
|
|
|
|
it('throws when env tenant is missing or inactive', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=missing-tenant');
|
|
|
|
expect(fn () => Tenant::current())->toThrow(
|
|
\RuntimeException::class,
|
|
'Configured INTUNE_TENANT_ID tenant is missing or inactive.'
|
|
);
|
|
|
|
restoreIntuneTenantId($originalEnv);
|
|
});
|
|
|
|
it('returns tenant marked as current when no env override', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
$current = Tenant::create([
|
|
'tenant_id' => 'tenant-current',
|
|
'name' => 'Current Tenant',
|
|
'is_current' => true,
|
|
]);
|
|
|
|
Tenant::create([
|
|
'tenant_id' => 'tenant-inactive',
|
|
'name' => 'Inactive Current Flag',
|
|
'status' => 'archived',
|
|
]);
|
|
|
|
$resolved = Tenant::current();
|
|
|
|
expect($resolved->id)->toBe($current->id);
|
|
|
|
restoreIntuneTenantId($originalEnv);
|
|
});
|
|
|
|
it('throws when no current tenant is selected', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
Tenant::create([
|
|
'tenant_id' => 'tenant-one',
|
|
'name' => 'Tenant One',
|
|
'is_current' => false,
|
|
]);
|
|
|
|
expect(fn () => Tenant::currentOrFail())->toThrow(\RuntimeException::class, 'No current tenant selected.');
|
|
|
|
restoreIntuneTenantId($originalEnv);
|
|
});
|
|
|
|
it('makeCurrent toggles flags within a transaction', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
$first = Tenant::create([
|
|
'tenant_id' => 'tenant-first',
|
|
'name' => 'First Tenant',
|
|
'is_current' => true,
|
|
]);
|
|
|
|
$second = Tenant::create([
|
|
'tenant_id' => 'tenant-second',
|
|
'name' => 'Second Tenant',
|
|
]);
|
|
|
|
$second->makeCurrent();
|
|
|
|
expect($second->fresh()->is_current)->toBeTrue();
|
|
expect($first->fresh()->is_current)->toBeFalse();
|
|
|
|
restoreIntuneTenantId($originalEnv);
|
|
});
|
|
|
|
it('makeCurrent keeps tenant current when already current', function () {
|
|
$originalEnv = getenv('INTUNE_TENANT_ID');
|
|
putenv('INTUNE_TENANT_ID=');
|
|
|
|
$current = Tenant::create([
|
|
'tenant_id' => 'tenant-current',
|
|
'name' => 'Already Current',
|
|
'is_current' => true,
|
|
]);
|
|
|
|
$other = Tenant::create([
|
|
'tenant_id' => 'tenant-other',
|
|
'name' => 'Other Tenant',
|
|
'is_current' => false,
|
|
]);
|
|
|
|
$current->makeCurrent();
|
|
|
|
expect($current->fresh()->is_current)->toBeTrue();
|
|
expect($other->fresh()->is_current)->toBeFalse();
|
|
|
|
restoreIntuneTenantId($originalEnv);
|
|
});
|