-
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-5196] updated EventTypes.kt, Messages.kt, refactored integration…
… tests - Added map for messageActionToEventType, used the same for emitting related message create, update and delete events - Refactored SandboxTest.kt, moved all of tests under `integration` package.
- Loading branch information
Showing
11 changed files
with
340 additions
and
209 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
195 changes: 0 additions & 195 deletions
195
chat-android/src/test/java/com/ably/chat/SandboxTest.kt
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
chat-android/src/test/java/com/ably/chat/integration/ConnectionIntegrationTest.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,40 @@ | ||
package com.ably.chat.integration | ||
|
||
import com.ably.chat.ConnectionStatus | ||
import com.ably.chat.ConnectionStatusChange | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
|
||
class ConnectionIntegrationTest { | ||
|
||
@Test | ||
fun `should observe connection status`() = runTest { | ||
val chatClient = sandbox.createSandboxChatClient() | ||
val connectionStatusChange = CompletableDeferred<ConnectionStatusChange>() | ||
chatClient.connection.onStatusChange { | ||
if (it.current == ConnectionStatus.Connected) connectionStatusChange.complete(it) | ||
} | ||
assertEquals( | ||
ConnectionStatusChange( | ||
current = ConnectionStatus.Connected, | ||
previous = ConnectionStatus.Connecting, | ||
error = null, | ||
retryIn = 0, | ||
), | ||
connectionStatusChange.await(), | ||
) | ||
} | ||
|
||
companion object { | ||
private lateinit var sandbox: Sandbox | ||
|
||
@JvmStatic | ||
@BeforeClass | ||
fun setUp() = runTest { | ||
sandbox = Sandbox.createInstance() | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
chat-android/src/test/java/com/ably/chat/integration/MessagesIntegrationTest.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,100 @@ | ||
package com.ably.chat.integration | ||
|
||
import com.ably.chat.Message | ||
import com.ably.chat.MessageEvent | ||
import com.ably.chat.MessageMetadata | ||
import com.ably.chat.RoomOptions | ||
import com.ably.chat.assertWaiter | ||
import io.ably.lib.types.MessageAction | ||
import java.util.UUID | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
|
||
class MessagesIntegrationTest { | ||
|
||
@Test | ||
fun `should be able to send and retrieve messages without room features`() = runTest { | ||
val chatClient = sandbox.createSandboxChatClient() | ||
val roomId = UUID.randomUUID().toString() | ||
|
||
val room = chatClient.rooms.get(roomId) | ||
|
||
room.attach() | ||
|
||
val messageEvent = CompletableDeferred<MessageEvent>() | ||
|
||
room.messages.subscribe { messageEvent.complete(it) } | ||
room.messages.send("hello") | ||
|
||
assertEquals( | ||
"hello", | ||
messageEvent.await().message.text, | ||
) | ||
} | ||
|
||
@Test | ||
fun `should be able to send and retrieve messages with all room features enabled`() = runTest { | ||
val chatClient = sandbox.createSandboxChatClient() | ||
val roomId = UUID.randomUUID().toString() | ||
|
||
val room = chatClient.rooms.get(roomId, RoomOptions.default) | ||
|
||
room.attach() | ||
|
||
val messageEvent = CompletableDeferred<MessageEvent>() | ||
|
||
room.messages.subscribe { messageEvent.complete(it) } | ||
room.messages.send("hello") | ||
|
||
assertEquals( | ||
"hello", | ||
messageEvent.await().message.text, | ||
) | ||
} | ||
|
||
@Test | ||
fun `should be able to send and retrieve messages from history`() = runTest { | ||
val chatClient = sandbox.createSandboxChatClient() | ||
val roomId = UUID.randomUUID().toString() | ||
|
||
val room = chatClient.rooms.get(roomId) | ||
|
||
room.attach() | ||
val metadata = MessageMetadata() | ||
metadata.addProperty("foo", "bar") | ||
|
||
room.messages.send("hello", metadata) | ||
|
||
lateinit var messages: List<Message> | ||
|
||
assertWaiter { | ||
messages = room.messages.get().items | ||
messages.isNotEmpty() | ||
} | ||
assertEquals(1, messages.size) | ||
val message = messages.first() | ||
|
||
assertEquals(roomId, message.roomId) | ||
assertEquals(MessageAction.MESSAGE_CREATE, message.action) | ||
assertEquals("hello", message.text) | ||
assertEquals("sandbox-client", message.clientId) | ||
assertTrue(message.serial.isNotEmpty()) | ||
assertEquals(message.serial, message.version) | ||
assertEquals(message.createdAt, message.timestamp) | ||
assertEquals(metadata.toString(), message.metadata.toString()) | ||
} | ||
|
||
companion object { | ||
private lateinit var sandbox: Sandbox | ||
|
||
@JvmStatic | ||
@BeforeClass | ||
fun setUp() = runTest { | ||
sandbox = Sandbox.createInstance() | ||
} | ||
} | ||
} |
Oops, something went wrong.