diff --git a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt index 3372450..2b26845 100644 --- a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt @@ -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" diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index 47f9731..343a6b1 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -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" diff --git a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt index 9c45f07..ca6a490 100644 --- a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt @@ -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 @@ -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? = 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() } @@ -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())) + }) + } } \ No newline at end of file