Skip to content

Commit 61cb6b2

Browse files
committed
[ECO-5517] Added comprehensive unit tests for liveobjects Helpers
1 parent 523dfe4 commit 61cb6b2

2 files changed

Lines changed: 458 additions & 9 deletions

File tree

live-objects/src/main/kotlin/io/ably/lib/objects/Helpers.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,20 @@ internal fun LiveObjectsAdapter.throwIfUnpublishableState(channelName: String) {
138138
}
139139

140140
// Spec: RTO2
141-
internal fun LiveObjectsAdapter.throwIfMissingChannelMode(channelName: String, channelMode: ChannelMode) {
142-
val channelModes = getChannelModes(channelName)
143-
if (channelModes == null || !channelModes.contains(channelMode)) {
144-
// Spec: RTO2a2, RTO2b2
145-
throw ablyException("\"${channelMode.name}\" channel mode must be set for this operation", ErrorCode.ChannelModeRequired)
141+
private fun LiveObjectsAdapter.throwIfMissingChannelMode(channelName: String, channelMode: ChannelMode) {
142+
getChannelModes(channelName)?.let { modes ->
143+
if (modes.contains(channelMode)) return // If channel modes are set, check if the required mode is present
146144
}
145+
// Spec: RTO2a2, RTO2b2
146+
throw ablyException("\"${channelMode.name}\" channel mode must be set for this operation", ErrorCode.ChannelModeRequired)
147147
}
148148

149-
internal fun LiveObjectsAdapter.throwIfInChannelState(channelName: String, channelStates: Array<ChannelState>) {
150-
val currentState = getChannel(channelName).state
151-
if (currentState == null || channelStates.contains(currentState)) {
152-
throw ablyException("Channel is in invalid state: $currentState", ErrorCode.ChannelStateError)
149+
private fun LiveObjectsAdapter.throwIfInChannelState(channelName: String, channelStates: Array<ChannelState>) {
150+
val currentChannelState = getChannel(channelName).state
151+
currentChannelState?.let {
152+
if (!channelStates.contains(it)) return
153153
}
154+
throw ablyException("Channel is in invalid state: $currentChannelState", ErrorCode.ChannelStateError)
154155
}
155156

156157
internal fun LiveObjectsAdapter.throwIfEchoMessagesDisabled() {

0 commit comments

Comments
 (0)