-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(resolvers): Add tests for header identity resolver (#27)
* chore: Add support for uppercase components in header parsing * test(resolvers): Add tests for header identity resolver
- Loading branch information
Showing
2 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Tests\Resolvers; | ||
|
||
use Illuminate\Config\Repository; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Routing\Router; | ||
use Orchestra\Testbench\Concerns\WithWorkbench; | ||
use Orchestra\Testbench\TestCase; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Sprout\Attributes\CurrentTenant; | ||
use Sprout\Contracts\Tenant; | ||
use Workbench\App\Models\TenantModel; | ||
|
||
class HeaderResolverTest extends TestCase | ||
{ | ||
use WithWorkbench, RefreshDatabase; | ||
|
||
protected $enablesPackageDiscoveries = true; | ||
|
||
protected function defineEnvironment($app): void | ||
{ | ||
tap($app['config'], static function (Repository $config) { | ||
$config->set('multitenancy.providers.tenants.model', TenantModel::class); | ||
$config->set('multitenancy.defaults.resolver', 'header'); | ||
}); | ||
} | ||
|
||
protected function defineRoutes($router) | ||
{ | ||
$router->get('/', function () { | ||
return 'no'; | ||
}); | ||
|
||
$router->tenanted(function (Router $router) { | ||
$router->get('/header-route', function (#[CurrentTenant] Tenant $tenant) { | ||
return $tenant->getTenantKey(); | ||
})->name('header.route'); | ||
}, 'header', 'tenants'); | ||
} | ||
|
||
#[Test] | ||
public function resolvesFromRoute(): void | ||
{ | ||
$tenant = TenantModel::first(); | ||
|
||
$result = $this->get(route('header.route'), ['Tenants-Identifier' => $tenant->getTenantIdentifier()]); | ||
|
||
$result->assertOk(); | ||
$result->assertContent((string)$tenant->getTenantKey()); | ||
} | ||
|
||
#[Test] | ||
public function throwsExceptionForInvalidTenant(): void | ||
{ | ||
$result = $this->get(route('header.route'), ['Tenants-Identifier' => 'i-am-not-real']); | ||
|
||
$result->assertInternalServerError(); | ||
} | ||
|
||
#[Test] | ||
public function throwsExceptionWithoutHeader(): void | ||
{ | ||
$result = $this->get(route('header.route')); | ||
|
||
$result->assertInternalServerError(); | ||
} | ||
} |