mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
[4.x] Set tenant as a default parameter for the URLs when using Path identification (#925)
* set tenant as default url parameter * Update PathIdentificationTest.php * assertion * test rename * fix tests * fix string Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
409190fae1
commit
f2c64088ed
2 changed files with 33 additions and 1 deletions
|
|
@ -18,7 +18,11 @@ beforeEach(function () {
|
|||
], function () {
|
||||
Route::get('/foo/{a}/{b}', function ($a, $b) {
|
||||
return "$a + $b";
|
||||
});
|
||||
})->name('foo');
|
||||
|
||||
Route::get('/baz/{a}/{b}', function ($a, $b) {
|
||||
return "$a - $b";
|
||||
})->name('baz');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -123,3 +127,23 @@ test('tenant parameter name can be customized', function () {
|
|||
->withoutExceptionHandling()
|
||||
->get('/acme/foo/abc/xyz');
|
||||
});
|
||||
|
||||
test('tenant parameter is set for all routes as the default parameter once the tenancy initialized', function () {
|
||||
Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
expect(tenancy()->initialized)->toBeFalse();
|
||||
|
||||
// make a request that will initialize tenancy
|
||||
pest()->get(route('foo', ['tenant' => 'acme', 'a' => 1, 'b' => 2]));
|
||||
|
||||
expect(tenancy()->initialized)->toBeTrue();
|
||||
expect(tenant('id'))->toBe('acme');
|
||||
|
||||
// assert that the route WITHOUT the tenant parameter matches the route WITH the tenant parameter
|
||||
expect(route('baz', ['a' => 1, 'b' => 2]))->toBe(route('baz', ['tenant' => 'acme', 'a' => 1, 'b' => 2]));
|
||||
|
||||
expect(route('baz', ['a' => 1, 'b' => 2]))->toBe('http://localhost/acme/baz/1/2'); // assert the full route string
|
||||
pest()->get(route('baz', ['a' => 1, 'b' => 2]))->assertOk(); // Assert route don't need tenant parameter
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue