-
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.
Added companion default for RoomOptions, added tests for the same
- Loading branch information
Showing
13 changed files
with
136 additions
and
46 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
92 changes: 92 additions & 0 deletions
92
chat-android/src/test/java/com/ably/chat/room/ConfigureRoomOptionsTest.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,92 @@ | ||
package com.ably.chat.room | ||
|
||
import com.ably.chat.ChatApi | ||
import com.ably.chat.DefaultRoom | ||
import com.ably.chat.RoomOptions | ||
import com.ably.chat.RoomStatus | ||
import com.ably.chat.TypingOptions | ||
import com.ably.utils.createMockRealtimeClient | ||
import io.ably.lib.types.AblyException | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert | ||
import org.junit.Assert.assertThrows | ||
import org.junit.Test | ||
|
||
/** | ||
* Chat rooms are configurable, so as to enable or disable certain features. | ||
* When requesting a room, options as to which features should be enabled, and | ||
* the configuration they should take, must be provided | ||
* Spec: CHA-RC2 | ||
*/ | ||
class ConfigureRoomOptionsTest { | ||
|
||
@Test | ||
fun `(CHA-RC2a) If a room is requested with a negative typing timeout, an ErrorInfo with code 40001 must be thrown`() = runTest { | ||
val mockRealtimeClient = createMockRealtimeClient() | ||
val chatApi = mockk<ChatApi>(relaxed = true) | ||
|
||
// Room success when positive typing timeout | ||
val room = DefaultRoom("1234", RoomOptions(typing = TypingOptions(timeoutMs = 100)), mockRealtimeClient, chatApi, null) | ||
Assert.assertNotNull(room) | ||
Assert.assertEquals(RoomStatus.Initialized, room.status) | ||
|
||
// Room failure when negative timeout | ||
val exception = assertThrows(AblyException::class.java) { | ||
DefaultRoom("1234", RoomOptions(typing = TypingOptions(timeoutMs = -1)), mockRealtimeClient, chatApi, null) | ||
} | ||
Assert.assertEquals("Typing timeout must be greater than 0", exception.errorInfo.message) | ||
Assert.assertEquals(40_001, exception.errorInfo.code) | ||
Assert.assertEquals(400, exception.errorInfo.statusCode) | ||
} | ||
|
||
@Test | ||
fun `(CHA-RC2b) Attempting to use disabled feature must result in an ErrorInfo with code 40000 being thrown`() = runTest { | ||
val mockRealtimeClient = createMockRealtimeClient() | ||
val chatApi = mockk<ChatApi>(relaxed = true) | ||
|
||
// Room only supports messages feature, since by default other features are turned off | ||
val room = DefaultRoom("1234", RoomOptions(), mockRealtimeClient, chatApi, null) | ||
Assert.assertNotNull(room) | ||
Assert.assertEquals(RoomStatus.Initialized, room.status) | ||
|
||
// Access presence throws exception | ||
var exception = assertThrows(AblyException::class.java) { | ||
room.presence | ||
} | ||
Assert.assertEquals("Presence is not enabled for this room", exception.errorInfo.message) | ||
Assert.assertEquals(40_000, exception.errorInfo.code) | ||
Assert.assertEquals(400, exception.errorInfo.statusCode) | ||
|
||
// Access reactions throws exception | ||
exception = assertThrows(AblyException::class.java) { | ||
room.reactions | ||
} | ||
Assert.assertEquals("Reactions are not enabled for this room", exception.errorInfo.message) | ||
Assert.assertEquals(40_000, exception.errorInfo.code) | ||
Assert.assertEquals(400, exception.errorInfo.statusCode) | ||
|
||
// Access typing throws exception | ||
exception = assertThrows(AblyException::class.java) { | ||
room.typing | ||
} | ||
Assert.assertEquals("Typing is not enabled for this room", exception.errorInfo.message) | ||
Assert.assertEquals(40_000, exception.errorInfo.code) | ||
Assert.assertEquals(400, exception.errorInfo.statusCode) | ||
|
||
// Access occupancy throws exception | ||
exception = assertThrows(AblyException::class.java) { | ||
room.occupancy | ||
} | ||
Assert.assertEquals("Occupancy is not enabled for this room", exception.errorInfo.message) | ||
Assert.assertEquals(40_000, exception.errorInfo.code) | ||
Assert.assertEquals(400, exception.errorInfo.statusCode) | ||
|
||
// room with all features | ||
val roomWithAllFeatures = DefaultRoom("1234", RoomOptions.default, mockRealtimeClient, chatApi, null) | ||
Assert.assertNotNull(roomWithAllFeatures.presence) | ||
Assert.assertNotNull(roomWithAllFeatures.reactions) | ||
Assert.assertNotNull(roomWithAllFeatures.typing) | ||
Assert.assertNotNull(roomWithAllFeatures.occupancy) | ||
} | ||
} |
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,3 @@ | ||
package com.ably.chat.room | ||
|
||
class RoomGetTest |
3 changes: 3 additions & 0 deletions
3
chat-android/src/test/java/com/ably/chat/room/RoomReleaseTest.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,3 @@ | ||
package com.ably.chat.room | ||
|
||
class RoomReleaseTest |
2 changes: 1 addition & 1 deletion
2
...est/java/com/ably/chat/room/AttachTest.kt → ...om/ably/chat/room/lifecycle/AttachTest.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
2 changes: 1 addition & 1 deletion
2
...est/java/com/ably/chat/room/DetachTest.kt → ...om/ably/chat/room/lifecycle/DetachTest.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
2 changes: 1 addition & 1 deletion
2
...java/com/ably/chat/room/PrecedenceTest.kt → ...bly/chat/room/lifecycle/PrecedenceTest.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
2 changes: 1 addition & 1 deletion
2
...st/java/com/ably/chat/room/ReleaseTest.kt → ...m/ably/chat/room/lifecycle/ReleaseTest.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
2 changes: 1 addition & 1 deletion
2
...test/java/com/ably/chat/room/RetryTest.kt → ...com/ably/chat/room/lifecycle/RetryTest.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
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