Skip to content

Commit

Permalink
test: Add test for non-tenant routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ollieread committed Nov 17, 2024
1 parent 8bee328 commit c42c5a7
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions tests/Http/Resolvers/SubdomainResolverTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Http\Resolvers;
namespace Sprout\Tests\Http\Resolvers;

use Illuminate\Config\Repository;
use Illuminate\Foundation\Testing\RefreshDatabase;
Expand All @@ -26,6 +26,7 @@ protected function defineEnvironment($app): void
tap($app['config'], static function (Repository $config) {
$config->set('multitenancy.providers.tenants.model', TenantModel::class);
$config->set('multitenancy.resolvers.subdomain.domain', 'localhost');
$config->set('session.driver', 'database');
});
}

Expand Down Expand Up @@ -59,19 +60,21 @@ protected function withoutParameterPattern($app): void

protected function defineRoutes($router)
{
$router->get('/', function () {
return 'no';
});

$router->tenanted(function (Router $router) {
$router->get('/subdomain-route', function (#[CurrentTenant] Tenant $tenant) {
$router->middleware('web')->group(function (Router $router) {
$router->get('/', function () {
return 'no';
});

$router->tenanted(function (Router $router) {
$router->get('/subdomain-route', function (#[CurrentTenant] Tenant $tenant) {
return $tenant->getTenantKey();
})->name('subdomain.route');
}, 'subdomain', 'tenants');

$router->get('/subdomain-request', function (#[CurrentTenant] Tenant $tenant) {
return $tenant->getTenantKey();
})->name('subdomain.route');
}, 'subdomain', 'tenants');

$router->get('/subdomain-request', function (#[CurrentTenant] Tenant $tenant) {
return $tenant->getTenantKey();
})->middleware('sprout.tenanted')->name('subdomain.request');
})->middleware('sprout.tenanted')->name('subdomain.request');
});
}

#[Test]
Expand All @@ -85,6 +88,15 @@ public function resolvesFromParameter(): void
$result->assertContent((string)$tenant->getTenantKey());
}

#[Test]
public function canAccessNonTenantedRoutesSuccessfully(): void
{
$result = $this->get('/');

$result->assertOk();
$result->assertContent('no');
}

#[Test]
public function resolvesWithoutParameter(): void
{
Expand Down

0 comments on commit c42c5a7

Please sign in to comment.