1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 21:14:03 +00:00

fix prefix test according to prefix changes

This commit is contained in:
Abrar Ahmad 2022-11-30 13:25:39 +05:00
parent 169a7f7cc9
commit 3407faf811

View file

@ -20,39 +20,40 @@ 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');
$prefixBase = config('tenancy.cache.prefix_base');
expect($originalPrefix) expect($originalPrefix . ':') // cache manager postfix ':' to prefix
->toBe(app('cache')->getPrefix()) ->toBe(app('cache')->getPrefix())
->toBe(app('cache.store')->getPrefix()); ->toBe(app('cache.store')->getPrefix());
$tenant1 = Tenant::create(); $tenant1 = Tenant::create();
$tenant2 = Tenant::create(); $tenant2 = Tenant::create();
$tenantOnePrefix = 'tenant_' . $tenant1->id . ':'; $tenantOnePrefix = $originalPrefix . $prefixBase . $tenant1->getTenantKey();
tenancy()->initialize($tenant1); tenancy()->initialize($tenant1);
cache()->set('key', 'tenantone-value'); 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());
$tenantTwoPrefix = 'tenant_' . $tenant2->id . ':'; $tenantTwoPrefix = $originalPrefix . $prefixBase . $tenant2->getTenantKey();
tenancy()->initialize($tenant2); tenancy()->initialize($tenant2);
cache()->set('key', 'tenanttwo-value'); 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 // Assert tenants' data is accessible using the prefix from the central context
tenancy()->end(); tenancy()->end();
config(['cache.prefix' => null]); // stop prefixing cache keys in central config(['cache.prefix' => null]); // stop prefixing cache keys in central so we can provide prefix manually
expect(cache($tenantOnePrefix . 'key'))->toBe('tenantone-value'); expect(cache($tenantOnePrefix . ':key'))->toBe('tenantone-value');
expect(cache($tenantTwoPrefix . 'key'))->toBe('tenanttwo-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 () {