Skip to content

Commit

Permalink
fix: latestAction -> action renaming + test
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Dec 6, 2024
1 parent cb58c0b commit 7627409
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
6 changes: 3 additions & 3 deletions chat-android/src/main/java/com/ably/chat/ChatApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class ChatApi(
method = "GET",
params = params,
) {
val latestActionName = it.requireJsonObject().get("latestAction")?.asString
val latestActionName = it.requireJsonObject().get("action")?.asString
val latestAction = latestActionName?.let { name -> messageActionNameToAction[name] }

latestAction?.let { action ->
Expand All @@ -47,7 +47,7 @@ internal class ChatApi(
createdAt = it.requireLong("createdAt"),
metadata = it.asJsonObject.get("metadata"),
headers = it.asJsonObject.get("headers")?.toMap() ?: mapOf(),
latestAction = action,
action = action,
)
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ internal class ChatApi(
createdAt = it.requireLong("createdAt"),
metadata = params.metadata,
headers = params.headers ?: mapOf(),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
)
} ?: throw AblyException.fromErrorInfo(ErrorInfo("Send message endpoint returned empty value", HttpStatusCode.InternalServerError))
}
Expand Down
2 changes: 1 addition & 1 deletion chat-android/src/main/java/com/ably/chat/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ data class Message(
/**
* The latest action of the message. This can be used to determine if the message was created, updated, or deleted.
*/
val latestAction: MessageAction,
val action: MessageAction,
)
2 changes: 1 addition & 1 deletion chat-android/src/main/java/com/ably/chat/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ internal class DefaultMessages(
text = data.text,
metadata = data.metadata,
headers = pubSubMessage.extras.asJsonObject().get("headers")?.toMap() ?: mapOf(),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
)
listener.onEvent(MessageEvent(type = MessageEventType.Created, message = chatMessage))
}
Expand Down
8 changes: 4 additions & 4 deletions chat-android/src/test/java/com/ably/chat/ChatApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ChatApiTest {
addProperty("clientId", "clientId")
addProperty("text", "hello")
addProperty("createdAt", 1_000_000)
addProperty("latestAction", "message.create")
addProperty("action", "message.create")
},
),
)
Expand All @@ -49,7 +49,7 @@ class ChatApiTest {
createdAt = 1_000_000L,
metadata = null,
headers = mapOf(),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
),
),
messages.items,
Expand All @@ -66,7 +66,7 @@ class ChatApiTest {
listOf(
JsonObject().apply {
addProperty("foo", "bar")
addProperty("latestAction", "message.create")
addProperty("action", "message.create")
},
),
)
Expand Down Expand Up @@ -103,7 +103,7 @@ class ChatApiTest {
createdAt = 1_000_000L,
headers = mapOf(),
metadata = null,
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
),
message,
)
Expand Down
4 changes: 2 additions & 2 deletions chat-android/src/test/java/com/ably/chat/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MessagesTest {
createdAt = 1_000_000,
metadata = JsonObject().apply { addProperty("meta", "data") },
headers = mapOf("foo" to "bar"),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
),
sentMessage,
)
Expand Down Expand Up @@ -135,7 +135,7 @@ class MessagesTest {
text = "some text",
metadata = null,
headers = mapOf("foo" to "bar"),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
),
messageEvent.message,
)
Expand Down
23 changes: 23 additions & 0 deletions chat-android/src/test/java/com/ably/chat/SandboxTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,29 @@ class SandboxTest {
)
}

@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()

room.messages.send("hello")

lateinit var messages: List<Message>

assertWaiter {
messages = room.messages.get().items
messages.isNotEmpty()
}

assertEquals(1, messages.size)
assertEquals("hello", messages.first().text)
assertEquals("sandbox-client", messages.first().clientId)
}

companion object {

private lateinit var sandbox: Sandbox
Expand Down
2 changes: 1 addition & 1 deletion chat-android/src/test/java/com/ably/chat/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun Occupancy.subscribeOnce(listener: Occupancy.Listener) {
}
}

suspend fun assertWaiter(timeoutInMs: Long = 10_000, block: () -> Boolean) {
suspend fun assertWaiter(timeoutInMs: Long = 10_000, block: suspend () -> Boolean) {
withContext(Dispatchers.Default) {
withTimeout(timeoutInMs) {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fun MessageBubblePreview() {
createdAt = System.currentTimeMillis(),
metadata = null,
headers = mapOf(),
latestAction = MessageAction.MESSAGE_CREATE,
action = MessageAction.MESSAGE_CREATE,
),
)
}
Expand Down

0 comments on commit 7627409

Please sign in to comment.