diff --git a/Sources/AblyChat/Room.swift b/Sources/AblyChat/Room.swift index 80e168b..20bf57c 100644 --- a/Sources/AblyChat/Room.swift +++ b/Sources/AblyChat/Room.swift @@ -423,3 +423,14 @@ internal actor DefaultRoom } } } + +#if DEBUG +extension DefaultRoom { + var testsOnly_lifecycleManager: DefaultRoomLifecycleManager { + guard let lifecycleManager = lifecycleManager as? DefaultRoomLifecycleManager else { + preconditionFailure("DefaultRoomLifecycleManager is expected here.") + } + return lifecycleManager + } +} +#endif diff --git a/Tests/AblyChatTests/DefaultRoomPresenceTests.swift b/Tests/AblyChatTests/DefaultRoomPresenceTests.swift index 710f21f..f2a4ba8 100644 --- a/Tests/AblyChatTests/DefaultRoomPresenceTests.swift +++ b/Tests/AblyChatTests/DefaultRoomPresenceTests.swift @@ -135,6 +135,41 @@ struct DefaultRoomPresenceTests { } } + // @spec CHA-PR3d + //@Test WIP + func usersMayEnterPresenceWhileAttaching() async throws { + // Given + let channelsList = [ + MockRealtimeChannel(name: "basketball::$chat::$chatMessages"), + ] + let channels = MockChannels(channels: channelsList) + let realtime = MockRealtime.create(channels: channels) + let room = try await DefaultRoom(realtime: realtime, chatAPI: ChatAPI(realtime: realtime), roomID: "basketball", options: .init(), logger: TestLogger(), lifecycleManagerFactory: MockRoomLifecycleManagerFactory()) + + let lifecycleManager = await room.testsOnly_lifecycleManager + let statusChangeWaitSubscription = await lifecycleManager.testsOnly_subscribeToStatusChangeWaitEvents() + + async let waitToBeAbleToPerformPresenceOperationsResult: Void = lifecycleManager.waitToBeAbleToPerformPresenceOperations(requestedByFeature: .presence) + + // Then: The manager waits for its room status to change + _ = try #require(await statusChangeWaitSubscription.first { _ in true }) + + // Then: The call to `waitToBeAbleToPerformPresenceOperations(requestedByFeature:)` succeeds + try await waitToBeAbleToPerformPresenceOperationsResult + + // Then + await #expect(throws: ARTErrorInfo.self) { + do { + try await room.presence.enter(data: ["status": "Online"]) + } catch { + let error = try #require(error as? ARTErrorInfo) + #expect(error.statusCode == 400) + #expect(error.localizedDescription.contains("attach")) + throw error + } + } + } + // @spec CHA-PR7a // @spec CHA-PR7b // @spec CHA-PR7c