diff --git a/Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift b/Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift index 2840837f..05bc5837 100644 --- a/Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift +++ b/Tests/AblyChatTests/DefaultRoomLifecycleManagerTests.swift @@ -73,14 +73,16 @@ struct DefaultRoomLifecycleManagerTests { initialState: ARTRealtimeChannelState = .initialized, feature: RoomFeature = .messages, // Arbitrarily chosen, its value only matters in test cases where we check which error is thrown attachBehavior: MockRoomLifecycleContributorChannel.AttachOrDetachBehavior? = nil, - detachBehavior: MockRoomLifecycleContributorChannel.AttachOrDetachBehavior? = nil + detachBehavior: MockRoomLifecycleContributorChannel.AttachOrDetachBehavior? = nil, + subscribeToStateBehavior: MockRoomLifecycleContributorChannel.SubscribeToStateBehavior? = nil ) -> MockRoomLifecycleContributor { .init( feature: feature, channel: .init( initialState: initialState, attachBehavior: attachBehavior, - detachBehavior: detachBehavior + detachBehavior: detachBehavior, + subscribeToStateBehavior: subscribeToStateBehavior ) ) } diff --git a/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift b/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift index 28f6723e..b363f875 100644 --- a/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift +++ b/Tests/AblyChatTests/Mocks/MockRoomLifecycleContributorChannel.swift @@ -4,6 +4,7 @@ final actor MockRoomLifecycleContributorChannel: RoomLifecycleContributorChannel { private let attachBehavior: AttachOrDetachBehavior? private let detachBehavior: AttachOrDetachBehavior? + private let subscribeToStateBehavior: SubscribeToStateBehavior var state: ARTRealtimeChannelState var errorReason: ARTErrorInfo? @@ -16,11 +17,13 @@ final actor MockRoomLifecycleContributorChannel: RoomLifecycleContributorChannel init( initialState: ARTRealtimeChannelState, attachBehavior: AttachOrDetachBehavior?, - detachBehavior: AttachOrDetachBehavior? + detachBehavior: AttachOrDetachBehavior?, + subscribeToStateBehavior: SubscribeToStateBehavior? ) { state = initialState self.attachBehavior = attachBehavior self.detachBehavior = detachBehavior + self.subscribeToStateBehavior = subscribeToStateBehavior ?? .justAddSubscription } enum AttachOrDetachResult { @@ -52,6 +55,11 @@ final actor MockRoomLifecycleContributorChannel: RoomLifecycleContributorChannel } } + enum SubscribeToStateBehavior { + case justAddSubscription + case addSubscriptionAndEmitStateChange(ARTChannelStateChange) + } + func attach() async throws(ARTErrorInfo) { attachCallCount += 1 @@ -100,6 +108,14 @@ final actor MockRoomLifecycleContributorChannel: RoomLifecycleContributorChannel func subscribeToState() -> Subscription { let subscription = Subscription(bufferingPolicy: .unbounded) subscriptions.append(subscription) + + switch subscribeToStateBehavior { + case .justAddSubscription: + break + case let .addSubscriptionAndEmitStateChange(stateChange): + emitStateChange(stateChange) + } + return subscription }