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

Merge branch 'master' of github.com:tenancy-for-laravel/v4

This commit is contained in:
Samuel Štancl 2024-10-11 23:01:25 +02:00
commit c199a6e0c8
2 changed files with 6 additions and 27 deletions

View file

@ -48,10 +48,6 @@ test('BroadcastChannelPrefixBootstrapper prefixes the channels events are broadc
$table->timestamps(); $table->timestamps();
}); });
universal_channel('users.{userId}', function ($user, $userId) {
return User::find($userId)->is($user);
});
$broadcaster = app(BroadcastManager::class)->driver(); $broadcaster = app(BroadcastManager::class)->driver();
$tenant = Tenant::create(); $tenant = Tenant::create();

View file

@ -138,14 +138,16 @@ test('broadcasting channel helpers register channels correctly', function() {
$tenantChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === "{tenant}.$channelName"); $tenantChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === "{tenant}.$channelName");
expect($tenantChannelClosure)->toBe($centralChannelClosure); expect($tenantChannelClosure)->toBe($centralChannelClosure);
// todo: fix tests from below here as the closure is now NOT modified, the $tenant parameter is expected (when additional parameters are used) and kept
// and the universal_channel() helper was removed (get rid of tests related to testing the helper's behavior, but tests which use universal channels should
// be kept -- the two channels should just be registered by hand per docs instead of using the now removed helper)
// The tenant channels are prefixed with '{tenant}.' // The tenant channels are prefixed with '{tenant}.'
// They accept the tenant key, but their closures only run in tenant context when tenancy is initialized // They accept the tenant key, but their closures only run in tenant context when tenancy is initialized
// The regular channels don't accept the tenant key, but they also respect the current context // The regular channels don't accept the tenant key, but they also respect the current context
// The tenant key is used solely for the name prefixing the closures can still run in the central context // The tenant key is used solely for the name prefixing the closures can still run in the central context
tenant_channel($channelName, $tenantChannelClosure = function ($user, $tenant, $userName) {
return User::firstWhere('name', $userName)?->is($user) ?? false;
});
expect($tenantChannelClosure)->not()->toBe($centralChannelClosure);
expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $centralUser->name))->toBeTrue(); expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $centralUser->name))->toBeTrue();
expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $tenantUser->name))->toBeFalse(); expect($tenantChannelClosure($centralUser, $tenant->getTenantKey(), $tenantUser->name))->toBeFalse();
@ -162,25 +164,6 @@ test('broadcasting channel helpers register channels correctly', function() {
expect($getChannels())->toBeEmpty(); expect($getChannels())->toBeEmpty();
// universal_channel helper registers both the unprefixed and the prefixed broadcasting channel correctly
// Using the tenant_channel helper + basic channel registration (Broadcast::channel())
universal_channel($channelName, $channelClosure);
// Regular channel registered correctly
$centralChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === $channelName);
expect($centralChannelClosure)->not()->toBeNull();
// Tenant channel registered correctly
$tenantChannelClosure = $getChannels()->first(fn ($closure, $name) => $name === "{tenant}.$channelName");
expect($tenantChannelClosure)
->not()->toBeNull() // Channel registered
->not()->toBe($centralChannelClosure); // The tenant channel callback is different after the auth user, it accepts the tenant ID
$broadcastManager->purge($driver);
$broadcastManager->extend($driver, fn () => new NullBroadcaster);
expect($getChannels())->toBeEmpty();
// Global channel helper prefixes the channel name with 'global__' // Global channel helper prefixes the channel name with 'global__'
global_channel($channelName, $channelClosure); global_channel($channelName, $channelClosure);