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

Improve tests (comments, use $tenant->id instead of $tenant->getTenantKey())

This commit is contained in:
lukinovec 2025-06-12 08:47:32 +02:00
parent 413247752d
commit a196b72ac7

View file

@ -41,7 +41,7 @@ test('CloneRoutesAsTenant action clones routes correctly', function (Route|null
$tenant = Tenant::create(); $tenant = Tenant::create();
expect($route->getName())->toBe($tenantRouteNamePrefix . str($route->getName())->afterLast(($tenantRouteNamePrefix))); expect($route->getName())->toBe($tenantRouteNamePrefix . str($route->getName())->afterLast(($tenantRouteNamePrefix)));
pest()->get(route($route->getName(), [$tenantParameterName => $tenant->getTenantKey()]))->assertOk(); pest()->get(route($route->getName(), [$tenantParameterName => $tenant->id]))->assertOk();
expect(tenancy()->getRouteMiddleware($route)) expect(tenancy()->getRouteMiddleware($route))
->toContain('tenant') ->toContain('tenant')
->not()->toContain('clone'); ->not()->toContain('clone');
@ -176,11 +176,11 @@ test('the clone action prefixes already prefixed routes correctly', function ()
expect($clonedRouteUrl) expect($clonedRouteUrl)
// Original prefix does not occur in the cloned route's URL // Original prefix does not occur in the cloned route's URL
->not()->toContain("prefix/{$tenant->getTenantKey()}/prefix") ->not()->toContain("prefix/{$tenant->id}/prefix")
->not()->toContain("//prefix") ->not()->toContain("//prefix")
->not()->toContain("prefix//") ->not()->toContain("prefix//")
// Route is prefixed correctly // Route is prefixed correctly
->toBe("http://localhost/prefix/{$tenant->getTenantKey()}/{$routes[$key]->getName()}"); ->toBe("http://localhost/prefix/{$tenant->id}/{$routes[$key]->getName()}");
// The cloned route is accessible // The cloned route is accessible
pest()->get($clonedRouteUrl)->assertOk(); pest()->get($clonedRouteUrl)->assertOk();
@ -208,11 +208,11 @@ test('clone action trims trailing slashes from prefixes given to nested route gr
expect($clonedLandingUrl) expect($clonedLandingUrl)
->not()->toContain("prefix//") ->not()->toContain("prefix//")
->toBe("http://localhost/prefix/{$tenant->getTenantKey()}"); ->toBe("http://localhost/prefix/{$tenant->id}");
expect($clonedHomeRouteUrl) expect($clonedHomeRouteUrl)
->not()->toContain("prefix//") ->not()->toContain("prefix//")
->toBe("http://localhost/prefix/{$tenant->getTenantKey()}/home"); ->toBe("http://localhost/prefix/{$tenant->id}/home");
}); });
test('tenant routes are ignored from cloning and clone middleware in groups causes no issues', function () { test('tenant routes are ignored from cloning and clone middleware in groups causes no issues', function () {
@ -221,26 +221,24 @@ test('tenant routes are ignored from cloning and clone middleware in groups caus
->middleware(['clone']) ->middleware(['clone'])
->name("tenant.route-with-tenant-parameter"); ->name("tenant.route-with-tenant-parameter");
// Should NOT be cloned // Should NOT be cloned, already has tenant name prefix
// The route already has tenant name prefix
RouteFacade::get("/route-with-tenant-name-prefix", fn () => true) RouteFacade::get("/route-with-tenant-name-prefix", fn () => true)
->middleware(['clone']) ->middleware(['clone'])
->name("tenant.route-with-tenant-name-prefix"); ->name("tenant.route-with-tenant-name-prefix");
// Should NOT be cloned // Should NOT be cloned, already has tenant parameter + 'clone' middleware in group
// The route already has a tenant parameter + 'clone' middleware in group // 'clone' MW in groups won't be removed (this doesn't cause any issues)
// 'clone' MW in groups won't be removed, this also doesn't cause any issues
RouteFacade::middlewareGroup('group', ['auth', 'clone']); RouteFacade::middlewareGroup('group', ['auth', 'clone']);
RouteFacade::get("/{tenant}/route-with-clone-in-mw-group", fn () => true) RouteFacade::get("/{tenant}/route-with-clone-in-mw-group", fn () => true)
->middleware('group') ->middleware('group')
->name("tenant.route-with-clone-in-mw-group"); ->name("tenant.route-with-clone-in-mw-group");
// SHOULD be cloned (with clone middleware) // SHOULD be cloned (has clone middleware)
RouteFacade::get('/foo', fn () => true) RouteFacade::get('/foo', fn () => true)
->middleware(['clone']) ->middleware(['clone'])
->name('foo'); ->name('foo');
// SHOULD be cloned (with nested clone middleware) // SHOULD be cloned (has nested clone middleware)
RouteFacade::get('/bar', fn () => true) RouteFacade::get('/bar', fn () => true)
->middleware(['group']) ->middleware(['group'])
->name('bar'); ->name('bar');