Skip to content

Commit

Permalink
test: Transfer call methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 27, 2024
1 parent e9753f1 commit 790762b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class AbstractTest {
protected val testUuid = UUID.fromString("aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab")
protected val toNumber = "447712345689"
protected val altNumber = "447700900001"
protected val text = "Hello, World!"
protected val networkCode = "65512"
protected val startTime = "2020-09-17T12:34:56Z"
protected val endTime = "2021-09-17T12:35:28Z"
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class MessagesTest : AbstractTest() {
private val whatsappChannel = "whatsapp"
private val viberChannel = "viber_service"
private val messengerChannel = "messenger"
private val text = "Hello, World!"
private val caption = "Additional text to accompany the media"
private val imageUrl = "https://example.com/image.jpg"
private val audioUrl = "https://example.com/audio.mp3"
Expand Down
33 changes: 31 additions & 2 deletions src/test/kotlin/com/vonage/client/kt/VoiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.vonage.client.kt
import com.vonage.client.voice.CallDirection
import com.vonage.client.voice.CallStatus
import com.vonage.client.voice.PhoneEndpoint
import com.vonage.client.voice.ncco.Ncco
import com.vonage.client.voice.ncco.TalkAction
import java.net.URI
import java.time.Instant
import java.util.*
import kotlin.test.Test
Expand All @@ -17,8 +20,18 @@ class VoiceTest : AbstractTest() {
private val callObj = voiceClient.call(UUID.fromString(callIdStr))
private val conversationId = "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"

private fun testModifyCall(actionName: String, invocation: () -> Unit) {
mockPut(expectedUrl = callUrl, expectedRequestParams = mapOf("action" to actionName), status = 204)
private fun testModifyCall(actionName: String = "transfer", invocation: () -> Unit,
nccoAction: Map<String, Any>? = null, nccoUrl: String? = null) {
mockPut(expectedUrl = callUrl,
expectedRequestParams = mapOf("action" to actionName) + (
if (actionName == "transfer") mapOf(
"destination" to mapOf("type" to "ncco") +
if (nccoUrl != null) mapOf("url" to listOf(nccoUrl))
else mapOf("ncco" to listOf(nccoAction))
) else mapOf()
),
status = 204
)
invocation.invoke()
}

Expand Down Expand Up @@ -101,4 +114,20 @@ class VoiceTest : AbstractTest() {
assertEquals(Instant.parse(endTime), response.endTime.toInstant())
assertEquals(networkCode, response.network)
}

@Test
fun `transfer call with answer url`() {
val answerUrl = "https://example.com/ncco.json"
testModifyCall(nccoUrl = answerUrl, invocation = {
callObj.transfer(URI.create(answerUrl))
callObj.transfer(answerUrl)
})
}

@Test
fun `transfer call with ncco`() {
testModifyCall(nccoAction = mapOf("action" to "talk", "text" to text), invocation = {
callObj.transfer(Ncco(TalkAction.builder(text).build()))
})
}
}

0 comments on commit 790762b

Please sign in to comment.