Skip to content

Commit

Permalink
Test for CHA-PR3d spec (WIP).
Browse files Browse the repository at this point in the history
  • Loading branch information
maratal committed Dec 31, 2024
1 parent 62d1e23 commit 174c33e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/AblyChat/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,14 @@ internal actor DefaultRoom<LifecycleManagerFactory: RoomLifecycleManagerFactory>
}
}
}

#if DEBUG
extension DefaultRoom {
var testsOnly_lifecycleManager: DefaultRoomLifecycleManager<DefaultRoomLifecycleContributor> {
guard let lifecycleManager = lifecycleManager as? DefaultRoomLifecycleManager<DefaultRoomLifecycleContributor> else {
preconditionFailure("DefaultRoomLifecycleManager is expected here.")
}
return lifecycleManager
}
}
#endif
35 changes: 35 additions & 0 deletions Tests/AblyChatTests/DefaultRoomPresenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 174c33e

Please sign in to comment.