-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECO-5147][CHA-RC3] Updated DefaultMessages implementation
1. Updated DefaultMessages constructor to accept 'room` as the only argument 2. Updated DefaultMessages.channel to accept merged options across shared features 3. Added extention method to 'RoomOptions', messagesChannelOptions, merged modes from all shared channels ( presence and occupancy ) 4. Fixed unit/integration tests related to Messages feature 5. Added test to check shared channel is accessed only once with combined modes+params
- Loading branch information
Showing
7 changed files
with
120 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
chat-android/src/test/java/com/ably/chat/room/RoomFeatureSharedChannelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.ably.chat.room | ||
|
||
import io.ably.lib.types.ChannelMode | ||
import io.ably.lib.types.ChannelOptions | ||
import io.mockk.every | ||
import io.mockk.verify | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
/** | ||
* Test to check shared channel for room features. | ||
* Spec: CHA-RC3 | ||
*/ | ||
class RoomFeatureSharedChannelTest { | ||
|
||
@Test | ||
fun `(CHA-RC3a) Features with shared channel should call channels#get only once with combined modes+options`() = runTest { | ||
val mockRealtimeClient = createMockRealtimeClient() | ||
val capturedChannelOptions = mutableListOf<ChannelOptions>() | ||
|
||
every { | ||
mockRealtimeClient.channels.get("1234::\$chat::\$chatMessages", any<ChannelOptions>()) | ||
} answers { | ||
capturedChannelOptions.add(secondArg()) | ||
mockRealtimeClient.createMockChannel() | ||
} | ||
|
||
// Create room with all feature enabled, | ||
val room = createMockRoom(realtimeClient = mockRealtimeClient) | ||
|
||
// Messages, occupancy and presence features uses the same channel | ||
Assert.assertEquals(room.messages.channel, room.presence.channel) | ||
Assert.assertEquals(room.messages.channel, room.occupancy.channel) | ||
|
||
// Reactions and typing uses independent channel | ||
Assert.assertNotEquals(room.messages.channel, room.typing.channel) | ||
Assert.assertNotEquals(room.messages.channel, room.reactions.channel) | ||
Assert.assertNotEquals(room.reactions.channel, room.typing.channel) | ||
|
||
Assert.assertEquals(1, capturedChannelOptions.size) | ||
// Check for set presence modes | ||
Assert.assertEquals(2, capturedChannelOptions[0].modes.size) | ||
Assert.assertEquals(ChannelMode.presence, capturedChannelOptions[0].modes[0]) | ||
Assert.assertEquals(ChannelMode.presence_subscribe, capturedChannelOptions[0].modes[1]) | ||
// Check if occupancy matrix is set | ||
Assert.assertEquals("metrics", capturedChannelOptions[0].params["occupancy"]) | ||
|
||
// channels.get is called only once for Messages, occupancy and presence since they share the same channel | ||
verify(exactly = 1) { | ||
mockRealtimeClient.channels.get("1234::\$chat::\$chatMessages", any<ChannelOptions>()) | ||
} | ||
// channels.get called separately for typing since it uses it's own channel | ||
verify(exactly = 1) { | ||
mockRealtimeClient.channels.get("1234::\$chat::\$typingIndicators", any<ChannelOptions>()) | ||
} | ||
// channels.get called separately for reactions since it uses it's own channel | ||
verify(exactly = 1) { | ||
mockRealtimeClient.channels.get("1234::\$chat::\$reactions", any<ChannelOptions>()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters