Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Aug 19, 2024
1 parent 655f84f commit c2cbcdb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 37 deletions.
3 changes: 3 additions & 0 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ abstract class AbstractTest {
protected val text = "Hello, World!"
protected val country = "GB"
protected val secret = "ABCDEFGH01234abc"
protected val vbcExt = "4321"
protected val userName = "Sam_username"
protected val sipUri = "sip:rebekka@sip.example.com"
protected val websocketUri = "wss://example.com/socket"
protected val wsContentType = "audio/l16;rate=8000"
protected val clientRef = "my-personal-reference"
protected val textHexEncoded = "48656c6c6f2c20576f726c6421"
protected val entityId = "1101407360000017170"
Expand Down
122 changes: 94 additions & 28 deletions src/test/kotlin/com/vonage/client/kt/UsersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.vonage.client.kt

import com.vonage.client.common.HttpMethod
import com.vonage.client.users.*
import com.vonage.client.users.channels.*
import java.net.URI
import kotlin.test.*

Expand All @@ -27,47 +28,112 @@ class UsersTest : AbstractTest() {
private val userId = "USR-82e028d9-5201-4f1e-8188-604b2d3471ec"
private val userUrl = "$baseUrl/$userId"
private val existingUser = client.user(userId)
private val name = "my_user_name"
private val displayName = "Test User"
private val ttl = 3600
private val ttl = 3600 // TODO support
private val pageSize = 10
private val customData = mapOf("custom_key" to "custom_value")
private val sipUser = "sip_user"
private val sipPassword = "Passw0rd1234"
private val messengerId = "12345abcd"
private val baseUserRequest = mapOf("name" to name)
private val cursor = "7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg="
private val href = "https://api.nexmo.com/users"
private val order = "desc"
private val navUrl = "$href?order=$order&page_size=$pageSize&cursor=$cursor"
private val navUrlMap = mapOf("href" to navUrl)
private val baseUserRequest = mapOf("name" to userName)
private val userIdMapOnly = mapOf("id" to userId)
private val baseUserResponse = userIdMapOnly + baseUserRequest
private val fullUserRequest = baseUserRequest + mapOf(
"display_name" to displayName,
"image_url" to imageUrl,
"properties" to mapOf(
"custom_data" to customData,
"ttl" to ttl
),
"custom_data" to customData,
"channels" to mapOf(
"pstn" to listOf(mapOf(
"number" to toNumber
)),
"sip" to listOf(mapOf(
"uri" to sipUri,
"username" to sipUser,
"password" to sipPassword
)),
"vbc" to listOf(mapOf(
"extension" to vbcExt
)),
"websocket" to listOf(mapOf(
"uri" to websocketUri,
"content-type" to wsContentType,
"headers" to customData
)),
"mms" to listOf(mapOf(
"number" to toNumber
)),
"whatsapp" to listOf(mapOf(
"number" to altNumber
)),
"viber" to listOf(mapOf(
"number" to altNumber
)),
"messenger" to listOf(mapOf(
"id" to messengerId
))
),
"properties" to mapOf(
"custom_data" to customData
)
)
private val fullUserResponse = userIdMapOnly + fullUserRequest

private fun assertEqualsUser(parsed: User) {
assertEquals(userId, parsed.id)
assertEquals(name, parsed.name)
assertEquals(userName, parsed.name)
assertEquals(displayName, parsed.displayName)
assertEquals(URI.create(imageUrl), parsed.imageUrl)
assertEquals(customData, parsed.customData)
val channels = parsed.channels
assertNotNull(channels)
// TODO the rest

val pstn = channels.pstn
assertNotNull(pstn)
assertEquals(1, pstn.size)
assertEquals(toNumber, pstn[0].number)

val mms = channels.mms
assertNotNull(mms)
assertEquals(1, mms.size)
assertEquals(toNumber, mms[0].number)

val whatsapp = channels.whatsapp
assertNotNull(whatsapp)
assertEquals(1, whatsapp.size)
assertEquals(altNumber, whatsapp[0].number)

val viber = channels.viber
assertNotNull(viber)
assertEquals(1, viber.size)
assertEquals(altNumber, viber[0].number)

val messenger = channels.messenger
assertNotNull(messenger)
assertEquals(1, messenger.size)
assertEquals(messengerId, messenger[0].id)

val websocket = channels.websocket
assertNotNull(websocket)
assertEquals(1, websocket.size)
assertEquals(URI.create(websocketUri), websocket[0].uri)
assertEquals(Websocket.ContentType.fromString(wsContentType), websocket[0].contentType)
assertEquals(customData, websocket[0].headers)

val sip = channels.sip
assertNotNull(sip)
assertEquals(1, sip.size)
assertEquals(URI.create(sipUri), sip[0].uri)
assertEquals(sipUser, sip[0].username)
assertEquals(sipPassword, sip[0].password)

val vbc = channels.vbc
assertNotNull(vbc)
assertEquals(1, vbc.size)
assertEquals(vbcExt, vbc[0].extension)
}

private fun assertUserNotFoundException(method: HttpMethod, invocation: Users.ExistingUser.() -> Any) =
Expand All @@ -93,7 +159,7 @@ class UsersTest : AbstractTest() {
mapOf(),
mapOf(
"id" to userId,
"name" to name,
"name" to userName,
"display_name" to displayName,
"_links" to mapOf(
"self" to mapOf(
Expand All @@ -106,17 +172,11 @@ class UsersTest : AbstractTest() {
),
"_links" to mapOf(
"first" to mapOf(
"href" to "https://api.nexmo.com/v1/users?order=desc&page_size=10"
),
"self" to mapOf(
"href" to "https://api.nexmo.com/v1/users?order=desc&page_size=10&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D"
),
"next" to mapOf(
"href" to "https://api.nexmo.com/v1/users?order=desc&page_size=10&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D"
"href" to "$href?order=$order&page_size=$pageSize"
),
"prev" to mapOf(
"href" to "https://api.nexmo.com/v1/users?order=desc&page_size=10&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D"
)
"self" to navUrlMap,
"next" to navUrlMap,
"prev" to navUrlMap
)
)
)
Expand Down Expand Up @@ -177,18 +237,23 @@ class UsersTest : AbstractTest() {
}

@Test
fun `create user all parameters`() {
fun `create user all parameters and channels`() {
mockPost(
expectedUrl = baseUrl, authType = authType,
expectedRequestParams = fullUserRequest,
expectedResponseParams = fullUserResponse
)
assertEqualsUser(client.create {
name(name)
name(userName)
displayName(displayName)
imageUrl(imageUrl)
customData(customData)
// TODO channels
channels(
Pstn(toNumber), Sip(sipUri, sipUser, sipPassword),
Websocket(websocketUri, Websocket.ContentType.fromString(wsContentType), customData),
Vbc(vbcExt.toInt()), Mms(toNumber), Whatsapp(altNumber),
Viber(altNumber), Messenger(messengerId)
)
})
}

Expand All @@ -201,13 +266,14 @@ class UsersTest : AbstractTest() {
@Test
fun `list users all filters`() {
assertListUsers(mapOf(
"page_size" to pageSize,
"order" to "desc",
"page_size" to pageSize
// TODO remaining filters
"cursor" to cursor,
"name" to userName
)) {
list {
order(ListUsersRequest.SortOrder.DESC)
pageSize(pageSize)
order(ListUsersRequest.SortOrder.DESC); name(userName)
pageSize(pageSize); cursor(URI.create(navUrl))
}
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/test/kotlin/com/vonage/client/kt/VoiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ class VoiceTest : AbstractTest() {
private val recordIndex = 14
private val dtmf = "p*123#"
private val fromPstn = "14155550100"
private val user = "Sam"
private val vbcExt = "4321"
private val streamUrl = "$exampleUrlBase/waiting.mp3"
private val onAnswerUrl = "$exampleUrlBase/ncco.json"
private val ringbackTone = "http://example.org/ringbackTone.wav"
private val wsContentType = "audio/l16;rate=8000"
private val userToUserHeader = "56a390f3d2b7310023a"
private val conversationName = "selective-audio Demo"
private val customHeaders = mapOf(
Expand Down Expand Up @@ -428,8 +425,8 @@ class VoiceTest : AbstractTest() {

@Test
fun `create call to App`() {
testCreateCallToSingleEndpoint(mapOf("type" to "app", "user" to user)) {
toApp(user)
testCreateCallToSingleEndpoint(mapOf("type" to "app", "user" to userName)) {
toApp(userName)
}
}

Expand Down Expand Up @@ -485,7 +482,7 @@ class VoiceTest : AbstractTest() {
"to" to listOf(
mapOf(
"type" to "app",
"user" to user
"user" to userName
),
mapOf(
"type" to phoneType,
Expand Down Expand Up @@ -532,7 +529,7 @@ class VoiceTest : AbstractTest() {
behavior(amdBehaviour); beepTimeout(beepTimeout); mode(amdMode)
}
to(
com.vonage.client.voice.AppEndpoint(user),
com.vonage.client.voice.AppEndpoint(userName),
com.vonage.client.voice.PhoneEndpoint(toNumber, dtmf),
com.vonage.client.voice.VbcEndpoint(vbcExt),
com.vonage.client.voice.WebSocketEndpoint(websocketUri, wsContentType, customHeaders),
Expand Down Expand Up @@ -608,8 +605,8 @@ class VoiceTest : AbstractTest() {
@Test
fun `create call with connect to App ncco`() {
testSingleNccoConnect(
mapOf("user" to user),
connectToApp(user)
mapOf("user" to userName),
connectToApp(userName)
)
}

Expand Down

0 comments on commit c2cbcdb

Please sign in to comment.