|
| 1 | +package com.ably.pubsub |
| 2 | + |
| 3 | +import io.ably.lib.realtime.AblyRealtime |
| 4 | +import io.ably.lib.realtime.RealtimeClient |
| 5 | +import io.ably.lib.realtime.RealtimeClientAdapter |
| 6 | +import io.ably.lib.realtime.channelOptions |
| 7 | +import io.ably.lib.types.ChannelMode |
| 8 | +import io.ably.lib.types.ChannelOptions |
| 9 | +import io.ably.lib.types.ClientOptions |
| 10 | +import kotlinx.coroutines.test.runTest |
| 11 | +import kotlin.test.Test |
| 12 | +import kotlin.test.assertEquals |
| 13 | +import kotlin.test.assertNull |
| 14 | +import kotlin.test.assertTrue |
| 15 | + |
| 16 | +class SdkWrapperAgentChannelParamTest { |
| 17 | + |
| 18 | + @Test |
| 19 | + fun `should add agent information to Realtime channels params`() = runTest { |
| 20 | + val javaRealtimeClient = createAblyRealtime() |
| 21 | + val realtimeClient = RealtimeClientAdapter(javaRealtimeClient) |
| 22 | + val wrapperSdkClient = |
| 23 | + realtimeClient.createWrapperSdkProxy(WrapperSdkProxyOptions(agents = mapOf("chat-android" to "0.1.0"))) |
| 24 | + |
| 25 | + // create channel from sdk proxy wrapper |
| 26 | + wrapperSdkClient.channels.get("chat-channel") |
| 27 | + |
| 28 | + // create channel without sdk proxy wrapper |
| 29 | + realtimeClient.channels.get("regular-channel") |
| 30 | + |
| 31 | + assertEquals( |
| 32 | + "chat-android/0.1.0", |
| 33 | + javaRealtimeClient.channels.get("chat-channel").channelOptions?.params?.get("agent") |
| 34 | + ) |
| 35 | + |
| 36 | + assertNull( |
| 37 | + javaRealtimeClient.channels.get("regular-channel").channelOptions?.params?.get("agent") |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + fun `should add agent information to Realtime channels params when channel created with custom options`() = runTest { |
| 43 | + val javaRealtimeClient = createAblyRealtime() |
| 44 | + val realtimeClient = RealtimeClient(javaRealtimeClient) |
| 45 | + val wrapperSdkClient = |
| 46 | + realtimeClient.createWrapperSdkProxy(WrapperSdkProxyOptions(agents = mapOf("chat-android" to "0.1.0"))) |
| 47 | + |
| 48 | + // create channel from sdk proxy wrapper |
| 49 | + wrapperSdkClient.channels.get("chat-channel", ChannelOptions().apply { |
| 50 | + params = mapOf("foo" to "bar") |
| 51 | + modes = arrayOf(ChannelMode.presence) |
| 52 | + }) |
| 53 | + |
| 54 | + // create channel without sdk proxy wrapper |
| 55 | + realtimeClient.channels.get("regular-channel", ChannelOptions().apply { |
| 56 | + encrypted = true |
| 57 | + }) |
| 58 | + |
| 59 | + assertEquals( |
| 60 | + "chat-android/0.1.0", |
| 61 | + javaRealtimeClient.channels.get("chat-channel").channelOptions?.params?.get("agent") |
| 62 | + ) |
| 63 | + |
| 64 | + assertEquals( |
| 65 | + "bar", |
| 66 | + javaRealtimeClient.channels.get("chat-channel").channelOptions?.params?.get("foo") |
| 67 | + ) |
| 68 | + |
| 69 | + assertEquals( |
| 70 | + ChannelMode.presence, |
| 71 | + javaRealtimeClient.channels.get("chat-channel").channelOptions?.modes?.get(0) |
| 72 | + ) |
| 73 | + |
| 74 | + assertNull( |
| 75 | + javaRealtimeClient.channels.get("regular-channel").channelOptions?.params?.get("agent") |
| 76 | + ) |
| 77 | + |
| 78 | + assertTrue( |
| 79 | + javaRealtimeClient.channels.get("regular-channel").channelOptions?.encrypted ?: false |
| 80 | + ) |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +private fun createAblyRealtime(): AblyRealtime { |
| 85 | + val options = ClientOptions("xxxxx:yyyyyyy").apply { |
| 86 | + autoConnect = false |
| 87 | + } |
| 88 | + return AblyRealtime(options) |
| 89 | +} |
0 commit comments