Skip to content

Commit

Permalink
Add a test for fetching room features
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-forooghian committed Nov 21, 2024
1 parent dbdde44 commit 1fe51a9
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tests/AblyChatTests/DefaultRoomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,48 @@ struct DefaultRoomTests {

// @specUntested CHA-RC2b - We chose to implement this failure with an idiomatic fatalError instead of throwing, but we can’t test this.

// This is just a basic sense check to make sure the room getters are working as expected, since we don’t have unit tests for some of the features at the moment.
@Test(arguments: [.messages, .presence, .reactions, .occupancy] as[RoomFeature])
func whenFeatureEnabled_propertyGetterReturns(feature: RoomFeature) async throws {
// Given: A RoomOptions with the (test argument `feature`) feature enabled in the room options
let roomOptions: RoomOptions = switch feature {
case .messages:
// Messages should always be enabled without needing any special options
.init()
case .presence:
.init(presence: .init())
case .reactions:
.init(reactions: .init())
case .occupancy:
.init(occupancy: .init())
default:
fatalError("Unexpected feature \(feature)")
}

let channelsList = [
MockRealtimeChannel(name: "basketball::$chat::$chatMessages"),
MockRealtimeChannel(name: "basketball::$chat::$reactions"),
]
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: roomOptions, logger: TestLogger(), lifecycleManagerFactory: MockRoomLifecycleManagerFactory())

// When: We call the room’s getter for that feature
// Then: It returns an object (i.e. does not `fatalError()`)
switch feature {
case .messages:
#expect(room.messages is DefaultMessages)
case .presence:
#expect(room.presence is DefaultPresence)
case .reactions:
#expect(room.reactions is DefaultRoomReactions)
case .occupancy:
#expect(room.occupancy is DefaultOccupancy)
default:
fatalError("Unexpected feature \(feature)")
}
}

// MARK: - Attach

@Test(
Expand Down

0 comments on commit 1fe51a9

Please sign in to comment.