1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 08:44:04 +00:00

Improve regression test

This commit is contained in:
lukinovec 2025-06-03 11:52:02 +02:00
parent 4c32599c57
commit 1748767b10

View file

@ -216,26 +216,42 @@ test('clone action trims trailing slashes from prefixes given to nested route gr
}); });
test('clone middleware within middleware groups is properly handled during cloning', function () { test('clone middleware within middleware groups is properly handled during cloning', function () {
// Define a middleware group that contains the 'clone' flag along with the 'auth' MW // Simple MW group with 'clone' flag
RouteFacade::middlewareGroup('mw-group-with-clone', ['auth', 'clone']); RouteFacade::middlewareGroup('simple-group', ['auth', 'clone']);
RouteFacade::get('/foo', fn () => true) // Define nested middleware groups 3 levels deep
->middleware('mw-group-with-clone') RouteFacade::middlewareGroup('level-3-group', ['clone']);
->name('foo'); RouteFacade::middlewareGroup('level-2-group', ['auth', 'level-3-group']);
RouteFacade::middlewareGroup('nested-group', ['web', 'level-2-group']);
// Create routes using both simple and nested middleware groups
RouteFacade::get('/simple', fn () => true)
->middleware('simple-group')
->name('simple');
RouteFacade::get('/nested', fn () => true)
->middleware('nested-group')
->name('nested');
app(CloneRoutesAsTenant::class)->handle(); app(CloneRoutesAsTenant::class)->handle();
// Route 'foo' should be cloned as 'tenant.foo' // Test simple middleware group handling
$clonedRoute = RouteFacade::getRoutes()->getByName('tenant.foo'); $clonedSimpleRoute = RouteFacade::getRoutes()->getByName('tenant.simple');
expect($clonedSimpleRoute)->not()->toBeNull();
expect($clonedRoute)->not()->toBeNull(); $simpleRouteMiddleware = tenancy()->getRouteMiddleware($clonedSimpleRoute);
expect($simpleRouteMiddleware)
->toContain('auth', 'tenant')
->not()->toContain('clone', 'simple-group');
$clonedRouteMiddleware = tenancy()->getRouteMiddleware($clonedRoute); // Test nested middleware group handling (3 levels deep)
$clonedNestedRoute = RouteFacade::getRoutes()->getByName('tenant.nested');
expect($clonedNestedRoute)->not()->toBeNull();
// The cloned route should still have other middleware from the group, $nestedRouteMiddleware = tenancy()->getRouteMiddleware($clonedNestedRoute);
// but it should NOT have the original middleware group name. expect($nestedRouteMiddleware)
// Instead, the middleware should be extracted from the group and applied directly. ->toContain('web', 'auth', 'tenant')
expect($clonedRouteMiddleware) ->not()->toContain('clone')
->toContain('auth') // Should not contain any group names - middleware should be extracted
->not()->toContain('test-group', 'clone'); ->not()->toContain('nested-group', 'level-2-group', 'level-3-group');
}); });