mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
assert tenants' data is accessible using the prefix from the central context
This commit is contained in:
parent
d6b4d9b7a7
commit
b920a2905e
1 changed files with 12 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ beforeEach(function () {
|
||||||
|
|
||||||
test('cache prefix is separate for each tenant', function () {
|
test('cache prefix is separate for each tenant', function () {
|
||||||
$originalPrefix = config('cache.prefix') . ':';
|
$originalPrefix = config('cache.prefix') . ':';
|
||||||
|
cache()->set('key', 'original-value');
|
||||||
|
|
||||||
expect($originalPrefix)
|
expect($originalPrefix)
|
||||||
->toBe(app('cache')->getPrefix())
|
->toBe(app('cache')->getPrefix())
|
||||||
|
|
@ -32,6 +33,8 @@ test('cache prefix is separate for each tenant', function () {
|
||||||
$tenantOnePrefix = 'tenant_' . $tenant1->id . ':';
|
$tenantOnePrefix = 'tenant_' . $tenant1->id . ':';
|
||||||
|
|
||||||
tenancy()->initialize($tenant1);
|
tenancy()->initialize($tenant1);
|
||||||
|
cache()->set('key', 'tenantone-value');
|
||||||
|
|
||||||
expect($tenantOnePrefix)
|
expect($tenantOnePrefix)
|
||||||
->toBe(app('cache')->getPrefix())
|
->toBe(app('cache')->getPrefix())
|
||||||
->toBe(app('cache.store')->getPrefix());
|
->toBe(app('cache.store')->getPrefix());
|
||||||
|
|
@ -39,9 +42,18 @@ test('cache prefix is separate for each tenant', function () {
|
||||||
$tenantTwoPrefix = 'tenant_' . $tenant2->id . ':';
|
$tenantTwoPrefix = 'tenant_' . $tenant2->id . ':';
|
||||||
|
|
||||||
tenancy()->initialize($tenant2);
|
tenancy()->initialize($tenant2);
|
||||||
|
cache()->set('key', 'tenanttwo-value');
|
||||||
|
|
||||||
expect($tenantTwoPrefix)
|
expect($tenantTwoPrefix)
|
||||||
->toBe(app('cache')->getPrefix())
|
->toBe(app('cache')->getPrefix())
|
||||||
->toBe(app('cache.store')->getPrefix());
|
->toBe(app('cache.store')->getPrefix());
|
||||||
|
|
||||||
|
// Assert tenants' data is accessible using the prefix from the central context
|
||||||
|
tenancy()->end();
|
||||||
|
config(['cache.prefix' => null]); // stop prefixing cache keys in central
|
||||||
|
|
||||||
|
expect(cache($tenantOnePrefix . 'key'))->toBe('tenantone-value');
|
||||||
|
expect(cache($tenantTwoPrefix . 'key'))->toBe('tenanttwo-value');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cache is persisted when reidentification is used', function () {
|
test('cache is persisted when reidentification is used', function () {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue