mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 17:44:05 +00:00
Add test for the new clone action addTenantParameter property
This commit is contained in:
parent
393f263f03
commit
ca57b89d02
1 changed files with 20 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ use Stancl\Tenancy\Actions\CloneRoutesAsTenant;
|
|||
use Stancl\Tenancy\Resolvers\PathTenantResolver;
|
||||
use Illuminate\Support\Facades\Route as RouteFacade;
|
||||
use function Stancl\Tenancy\Tests\pest;
|
||||
use Illuminate\Routing\Exceptions\UrlGenerationException;
|
||||
|
||||
test('CloneRoutesAsTenant action clones routes with clone middleware by default', function () {
|
||||
config(['tenancy.identification.resolvers.' . PathTenantResolver::class . '.tenant_parameter_name' => 'team']);
|
||||
|
|
@ -337,3 +338,22 @@ test('clone action can be used fluently', function() {
|
|||
expect(collect(RouteFacade::getRoutes()->get())->map->getName())
|
||||
->toContain('tenant.foo', 'tenant.bar', 'tenant.baz');
|
||||
});
|
||||
|
||||
test('addTenantParameter affects if the cloned route will have the tenant parameter', function(bool $addTenantParameter) {
|
||||
RouteFacade::get('/foo', fn () => true)->name('foo')->middleware('clone');
|
||||
|
||||
$cloneAction = app(CloneRoutesAsTenant::class);
|
||||
|
||||
$cloneAction->addTenantParameter($addTenantParameter)->handle();
|
||||
|
||||
$clonedRoute = RouteFacade::getRoutes()->getByName('tenant.foo');
|
||||
|
||||
if ($addTenantParameter) {
|
||||
expect($clonedRoute->uri())->toContain('{tenant}');
|
||||
expect(fn () => $this->get(route('tenant.foo')))->toThrow(UrlGenerationException::class, 'Missing parameter: tenant');
|
||||
$this->withoutExceptionHandling()->get(route('tenant.foo', ['tenant' => Tenant::create()->id]))->assertOk();
|
||||
} else {
|
||||
expect($clonedRoute->uri())->not()->toContain('{tenant}');
|
||||
$this->withoutExceptionHandling()->get(route('tenant.foo'))->assertOk();
|
||||
}
|
||||
})->with([true, false]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue