From e47096e95bbd858f4146db23fddc2f25a1b545a4 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Thu, 26 Sep 2024 15:53:15 -0300 Subject: [PATCH] make it so that you can always get default values of manager this is so that we can create test factories that allow us to test the default behaviour except for specific overrides --- Sources/AblyChat/RoomLifecycleManager.swift | 8 ++++---- Tests/AblyChatTests/RoomLifecycleManagerTests.swift | 9 +-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Sources/AblyChat/RoomLifecycleManager.swift b/Sources/AblyChat/RoomLifecycleManager.swift index fa856a87..4ea178f2 100644 --- a/Sources/AblyChat/RoomLifecycleManager.swift +++ b/Sources/AblyChat/RoomLifecycleManager.swift @@ -31,7 +31,7 @@ internal actor RoomLifecycleManager { internal init(contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { self.init( - current: .initialized, + current: nil, contributors: contributors, logger: logger, clock: clock @@ -39,7 +39,7 @@ internal actor RoomLifecycleManager { } #if DEBUG - internal init(testsOnly_current current: RoomLifecycle, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { + internal init(testsOnly_current current: RoomLifecycle? = nil, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { self.init( current: current, contributors: contributors, @@ -49,8 +49,8 @@ internal actor RoomLifecycleManager { } #endif - private init(current: RoomLifecycle, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { - self.current = current + private init(current: RoomLifecycle?, contributors: [Contributor], logger: InternalLogger, clock: SimpleClock) { + self.current = current ?? .initialized self.contributors = contributors self.logger = logger self.clock = clock diff --git a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift index e83f8cd8..312e85d4 100644 --- a/Tests/AblyChatTests/RoomLifecycleManagerTests.swift +++ b/Tests/AblyChatTests/RoomLifecycleManagerTests.swift @@ -28,14 +28,7 @@ struct RoomLifecycleManagerTests { } private func createManager( - contributors: [RoomLifecycleManager.Contributor] = [], - clock: SimpleClock = MockSimpleClock() - ) -> RoomLifecycleManager { - .init(contributors: contributors, logger: TestLogger(), clock: clock) - } - - private func createManager( - forTestingWhatHappensWhenCurrentlyIn current: RoomLifecycle, + forTestingWhatHappensWhenCurrentlyIn current: RoomLifecycle? = nil, contributors: [RoomLifecycleManager.Contributor] = [], clock: SimpleClock = MockSimpleClock() ) -> RoomLifecycleManager {