From a13110c88002ca9bbbc4a843199b972e663e1e37 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 29 Jul 2025 12:19:04 +0200 Subject: [PATCH] Test real usage with slack channel (the bootstrapper updates the webhook used by the slack channel correctly) --- .../LogTenancyBootstrapperTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/Bootstrappers/LogTenancyBootstrapperTest.php b/tests/Bootstrappers/LogTenancyBootstrapperTest.php index 70f775f2..c5613b9e 100644 --- a/tests/Bootstrappers/LogTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/LogTenancyBootstrapperTest.php @@ -347,3 +347,54 @@ test('stack logs are written to all configured channels with tenant-specific pat ->toContain('central') ->not()->toContain('tenant'); }); + +test('slack channel uses correct webhook urls', function () { + config([ + 'logging.default' => 'slack', + 'logging.channels.slack.url' => 'central-webhook', + 'logging.channels.slack.level' => 'debug', // Set level to debug to keep the tests simple, since the default level here is 'critical' + ]); + + $tenant1 = Tenant::create(['id' => 'tenant1', 'slackUrl' => 'tenant1-webhook']); + $tenant2 = Tenant::create(['id' => 'tenant2', 'slackUrl' => 'tenant2-webhook']); + + LogTenancyBootstrapper::$channelOverrides = [ + 'slack' => ['url' => 'slackUrl'], + ]; + + // Test central context - should attempt to use central webhook + try { + logger('central'); + } catch (Exception $e) { + expect($e->getMessage())->toContain('central-webhook'); + } + + // Test tenant 1 context - should attempt to use tenant1 webhook + tenancy()->initialize($tenant1); + + try { + logger('tenant1'); + } catch (Exception $e) { + expect($e->getMessage())->toContain('tenant1-webhook'); + } + + tenancy()->end(); + + // Test tenant 2 context - should attempt to use tenant2 webhook + tenancy()->initialize($tenant2); + + try { + logger('tenant2'); + } catch (Exception $e) { + expect($e->getMessage())->toContain('tenant2-webhook'); + } + + tenancy()->end(); + + // Back to central - should use central webhook again + try { + logger('central'); + } catch (Exception $e) { + expect($e->getMessage())->toContain('central-webhook'); + } +});