mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 05:44:04 +00:00
UrlGenerator: set defaults based on config; request data: move config to config file+resolver
This commit is contained in:
parent
27685ffe5a
commit
bba649a33c
6 changed files with 139 additions and 33 deletions
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
use Illuminate\Support\Facades\Route;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByRequestDataException;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
|
||||
use Stancl\Tenancy\Resolvers\RequestDataTenantResolver;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use function Stancl\Tenancy\Tests\pest;
|
||||
|
||||
|
|
@ -13,12 +14,11 @@ beforeEach(function () {
|
|||
'tenancy.identification.central_domains' => [
|
||||
'localhost',
|
||||
],
|
||||
'tenancy.identification.' . RequestDataTenantResolver::class . '.header' => 'X-Tenant',
|
||||
'tenancy.identification.' . RequestDataTenantResolver::class . '.query_parameter' => 'tenant',
|
||||
'tenancy.identification.' . RequestDataTenantResolver::class . '.cookie' => 'tenant',
|
||||
]);
|
||||
|
||||
InitializeTenancyByRequestData::$header = 'X-Tenant';
|
||||
InitializeTenancyByRequestData::$cookie = 'X-Tenant';
|
||||
InitializeTenancyByRequestData::$queryParameter = 'tenant';
|
||||
|
||||
Route::middleware(['tenant', InitializeTenancyByRequestData::class])->get('/test', function () {
|
||||
return 'Tenant id: ' . tenant('id');
|
||||
});
|
||||
|
|
@ -48,11 +48,13 @@ test('cookie identification works', function () {
|
|||
|
||||
$this
|
||||
->withoutExceptionHandling()
|
||||
->withUnencryptedCookie('X-Tenant', $tenant->id)
|
||||
->withUnencryptedCookie('tenant', $tenant->id)
|
||||
->get('test')
|
||||
->assertSee($tenant->id);
|
||||
});
|
||||
|
||||
// todo@tests encrypted cookie
|
||||
|
||||
test('middleware throws exception when tenant data is not provided in the request', function () {
|
||||
pest()->expectException(TenantCouldNotBeIdentifiedByRequestDataException::class);
|
||||
$this->withoutExceptionHandling()->get('test');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue