From 492fba81eb3e4b49f39866f7be707772081520cb Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 13 Nov 2024 11:46:28 +0000 Subject: [PATCH] [ECO-5082] chore: add sandbox for presence --- .../src/main/java/com/ably/chat/Presence.kt | 9 +++++---- .../src/test/java/com/ably/chat/SandboxTest.kt | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/chat-android/src/main/java/com/ably/chat/Presence.kt b/chat-android/src/main/java/com/ably/chat/Presence.kt index af750ab..c0ffa9d 100644 --- a/chat-android/src/main/java/com/ably/chat/Presence.kt +++ b/chat-android/src/main/java/com/ably/chat/Presence.kt @@ -31,7 +31,8 @@ interface Presence : EmitsDiscontinuities { /** * Method to get list of the current online users and returns the latest presence messages associated to it. * @param {Ably.RealtimePresenceParams} params - Parameters that control how the presence set is retrieved. - * @returns {List} or upon failure, the promise will throw [[Ably.ErrorInfo]] object which explains the error. + * @throws {@link io.ably.lib.types.AblyException} object which explains the error. + * @returns {List} */ suspend fun get(waitForSync: Boolean = true, clientId: String? = null, connectionId: String? = null): List @@ -45,21 +46,21 @@ interface Presence : EmitsDiscontinuities { /** * Method to join room presence, will emit an enter event to all subscribers. Repeat calls will trigger more enter events. * @param {PresenceData} data - The users data, a JSON serializable object that will be sent to all subscribers. - * @returns {Promise} or upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @throws {@link io.ably.lib.types.AblyException} object which explains the error. */ suspend fun enter(data: PresenceData? = null) /** * Method to update room presence, will emit an update event to all subscribers. If the user is not present, it will be treated as a join event. * @param {PresenceData} data - The users data, a JSON serializable object that will be sent to all subscribers. - * @returns {Promise} or upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @throws {@link io.ably.lib.types.AblyException} object which explains the error. */ suspend fun update(data: PresenceData? = null) /** * Method to leave room presence, will emit a leave event to all subscribers. If the user is not present, it will be treated as a no-op. * @param {PresenceData} data - The users data, a JSON serializable object that will be sent to all subscribers. - * @returns {Promise} or upon failure, the promise will be rejected with an {@link ErrorInfo} object which explains the error. + * @throws {@link io.ably.lib.types.AblyException} object which explains the error. */ suspend fun leave(data: PresenceData? = null) diff --git a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt index 0411e58..9c459af 100644 --- a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt +++ b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt @@ -1,6 +1,5 @@ package com.ably.chat -import io.ably.lib.realtime.ChannelState import java.util.UUID import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals @@ -17,10 +16,22 @@ class SandboxTest { } @Test - fun basicIntegrationTest() = runTest { + fun `should return empty list of presence members if nobody is entered`() = runTest { val chatClient = sandbox.createSandboxChatClient() val room = chatClient.rooms.get(UUID.randomUUID().toString()) room.attach() - assertEquals(ChannelState.attached, room.messages.channel.state) + val members = room.presence.get() + assertEquals(0, members.size) + } + + @Test + fun `should return yourself as presence member after you entered`() = runTest { + val chatClient = sandbox.createSandboxChatClient() + val room = chatClient.rooms.get(UUID.randomUUID().toString()) + room.attach() + room.presence.enter() + val members = room.presence.get() + assertEquals(1, members.size) + assertEquals("sandbox-client", members.first().clientId) } }