1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 12:34:03 +00:00

Add test that covers how tenant_asset() works when called in central context

Added to cover the `return storage_path('app/public')` line in TenantAssetController::assetRoot
This commit is contained in:
lukinovec 2026-08-20 15:34:02 +02:00 committed by Samuel Stancl
parent 1a693d8e36
commit 4826667ac1

View file

@ -31,6 +31,7 @@ beforeEach(function () {
TenancyUrlGenerator::$passTenantParameterToRoutes = true;
TenantAssetController::$headers = [];
TenantAssetController::$publicDisk = null;
InitializeTenancyByRequestData::$onFail = null;
/** @var CloneRoutesAsTenant $cloneAction */
$cloneAction = app(CloneRoutesAsTenant::class);
@ -130,6 +131,21 @@ test('tenant asset controller throws when the configured disk has no root', func
pest()->get(tenant_asset('foo.txt'), ['X-Tenant' => $tenant->id]);
});
test('tenant assets are served from the central storage path in central context', function () {
config(['tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class]);
// Mimic the universal route setup (let the request through even though no tenant is identified)
InitializeTenancyByRequestData::$onFail = fn ($e, $request, $next) => $next($request);
$filename = 'testfile' . Str::random(8);
Storage::disk('public')->put($filename, 'bar');
$response = pest()->get(tenant_asset($filename));
$response->assertSuccessful();
expect($response->getFile()->getPathname())->toBe(storage_path("app/public/$filename"));
});
test('asset helper returns a link to tenant asset controller when asset url is null', function () {
config(['app.asset_url' => null]);
config(['tenancy.filesystem.asset_helper_override' => true]);