Skip to content

Commit

Permalink
Add tests for lifecycle contributor precedence
Browse files Browse the repository at this point in the history
We had already implemented these but didn’t have tests.

Resolves #153.
  • Loading branch information
lawrence-forooghian committed Dec 4, 2024
1 parent 2b2bfc0 commit 2a697a7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Tests/AblyChatTests/DefaultRoomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ struct DefaultRoomTests {
#expect(Set(channelsGetArguments.map(\.name)) == Set(expectedFetchedChannelNames))
}

// @spec CHA-RC2e
// @spec CHA-RL10
@Test
func lifecycleContributorOrder() async throws {
// Given: a DefaultRoom, instance, with all room features enabled
let channelsList = [
MockRealtimeChannel(name: "basketball::$chat::$chatMessages"),
MockRealtimeChannel(name: "basketball::$chat::$reactions"),
MockRealtimeChannel(name: "basketball::$chat::$typingIndicators"),
]
let channels = MockChannels(channels: channelsList)
let realtime = MockRealtime.create(channels: channels)
let lifecycleManagerFactory = MockRoomLifecycleManagerFactory()
_ = try await DefaultRoom(realtime: realtime, chatAPI: ChatAPI(realtime: realtime), roomID: "basketball", options: .allFeaturesEnabled, logger: TestLogger(), lifecycleManagerFactory: lifecycleManagerFactory)

// Then: The array of contributors with which it initializes the RoomLifecycleManager are in the same order as the following list:
//
// messages, presence, typing, reactions, occupancy
//
// (note that we do not say that it is the _same_ list, because we combine multiple features into a single contributor)
let lifecycleManagerCreationArguments = try #require(await lifecycleManagerFactory.createManagerArguments.first)
#expect(lifecycleManagerCreationArguments.contributors.map(\.feature) == [.messages, .typing, .reactions])
}

// @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.
Expand Down

0 comments on commit 2a697a7

Please sign in to comment.