diff --git a/src/Http/Resolvers/HeaderIdentityResolver.php b/src/Http/Resolvers/HeaderIdentityResolver.php index 984a463..a881648 100644 --- a/src/Http/Resolvers/HeaderIdentityResolver.php +++ b/src/Http/Resolvers/HeaderIdentityResolver.php @@ -38,9 +38,9 @@ public function getHeader(): string public function getRequestHeaderName(Tenancy $tenancy): string { return str_replace( - ['{tenancy}', '{resolver}'], - [$tenancy->getName(), $this->getName()], - $this->header + ['{tenancy}', '{resolver}', '{Tenancy}', '{Resolver}'], + [$tenancy->getName(), $this->getName(), ucfirst($tenancy->getName()), ucfirst($this->getName())], + $this->getHeader() ); } diff --git a/tests/Resolvers/HeaderResolverTest.php b/tests/Resolvers/HeaderResolverTest.php new file mode 100644 index 0000000..0de95d6 --- /dev/null +++ b/tests/Resolvers/HeaderResolverTest.php @@ -0,0 +1,69 @@ +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(); + } +}