Skip to content

Commit

Permalink
Rename test clients, repurpose VonageTest
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Sep 4, 2024
1 parent 953f0cc commit 612b801
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 66 deletions.
6 changes: 3 additions & 3 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ abstract class AbstractTest {
)

val vonage = Vonage {
apiKey(apiKey); apiSecret(apiSecret);
applicationId(applicationId); privateKeyPath(privateKeyPath)
httpConfig {
authFromEnv(); httpConfig {
baseUri("http://localhost:$port")
}
apiKey(apiKey); apiSecret(apiSecret); signatureSecret(null)
applicationId(applicationId); privateKeyPath(privateKeyPath)
}

@BeforeEach
Expand Down
16 changes: 8 additions & 8 deletions src/test/kotlin/com/vonage/client/kt/AccountTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.junit.jupiter.api.assertThrows
import kotlin.test.*

class AccountTest : AbstractTest() {
private val account = vonage.account
private val client = vonage.account
private val authType = AuthType.API_KEY_SECRET_HEADER
private val secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"
private val trx = "8ef2447e69604f642ae59363aa5f781b"
Expand All @@ -30,8 +30,8 @@ class AccountTest : AbstractTest() {
private val secretsAltUrl = "${baseUrl}s/$apiKey2/secrets"
private val secretUrl = "$secretsUrl/$secretId"
private val altSecretUrl = "$secretsAltUrl/$secretId"
private val secretsNoApiKey = account.secrets()
private val secretsWithApiKey = account.secrets(apiKey2)
private val secretsNoApiKey = client.secrets()
private val secretsWithApiKey = client.secrets(apiKey2)
private val errorCode = 401
private val secretResponse = linksSelfHref(secretUrl) + mapOf(
"id" to secretId,
Expand Down Expand Up @@ -60,7 +60,7 @@ class AccountTest : AbstractTest() {
)
)

val response = invocation(account)
val response = invocation(client)
assertNotNull(response)
assertEquals(moCallbackUrl, response.incomingSmsUrl)
assertEquals(drCallbackUrl, response.deliveryReceiptUrl)
Expand Down Expand Up @@ -159,7 +159,7 @@ class AccountTest : AbstractTest() {
)
)

val response = account.getBalance()
val response = client.getBalance()
assertNotNull(response)
assertEquals(value, response.value)
assertEquals(autoReload, response.isAutoReload)
Expand All @@ -172,7 +172,7 @@ class AccountTest : AbstractTest() {
status = errorCode, authType = authType,
expectedResponseParams = errorResponse
)
assertThrows<AccountResponseException> { account.getBalance() }
assertThrows<AccountResponseException> { client.getBalance() }
}

@Test
Expand All @@ -186,7 +186,7 @@ class AccountTest : AbstractTest() {
"error-code-label" to "success"
)
)
account.topUp(trx)
client.topUp(trx)
}

@Test
Expand All @@ -198,7 +198,7 @@ class AccountTest : AbstractTest() {
expectedResponseParams = errorResponse
)

assertThrows<AccountResponseException> { account.topUp(trx) }
assertThrows<AccountResponseException> { client.topUp(trx) }
}

@Test
Expand Down
14 changes: 7 additions & 7 deletions src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import com.vonage.client.common.Webhook
import kotlin.test.*

class ApplicationTest : AbstractTest() {
private val ac = vonage.application
private val client = vonage.application
private val authType = AuthType.API_KEY_SECRET_HEADER
private val existingApplication = ac.application(testUuid)
private val existingApplication = client.application(testUuid)
private val baseUrl = "/v2/applications"
private val appUrl = "$baseUrl/$testUuid"
private val answerUrl = "$exampleUrlBase/answer"
Expand Down Expand Up @@ -266,18 +266,18 @@ class ApplicationTest : AbstractTest() {

@Test
fun `list all applications`() {
assertListApplications { ac.listAll() }
assertListApplications { client.listAll() }
}

@Test
fun `list applications no filter`() {
assertListApplications { ac.list() }
assertListApplications { client.list() }
}

@Test
fun `list applications all filters`() {
assertListApplications(mapOf("page" to page, "page_size" to pageSize)) {
ac.list(page, pageSize)
client.list(page, pageSize)
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ class ApplicationTest : AbstractTest() {
expectedRequestParams = advancedApplicationRequest,
expectedResponseParams = fullApplicationResponse
)
assertEqualsFullApplication(ac.create {
assertEqualsFullApplication(client.create {
name(name)
publicKey(publicKey)
voice {
Expand Down Expand Up @@ -369,7 +369,7 @@ class ApplicationTest : AbstractTest() {
})

assert401ApiResponseException<ApplicationResponseException>(baseUrl, HttpMethod.POST) {
ac.create { name(name) }
client.create { name(name) }
}
}
}
7 changes: 3 additions & 4 deletions src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import com.vonage.client.messages.whatsapp.Policy
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.net.URI
import java.time.Instant
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

class MessagesTest : AbstractTest() {
private val messagesClient = vonage.messages
private val client = vonage.messages
private val sendUrl = "/v1/messages"
private val messageUuid = testUuid
private val mmsChannel = "mms"
Expand All @@ -48,7 +47,7 @@ class MessagesTest : AbstractTest() {
expectedUrl = sendUrl, expectedRequestParams = expectedBodyParams,
status = status, expectedResponseParams = expectedResponseParams
)
assertEquals(messageUuid, messagesClient.send(req))
assertEquals(messageUuid, client.send(req))
}

private fun baseBody(messageType: String, channel: String): Map<String, Any> =
Expand Down Expand Up @@ -84,7 +83,7 @@ class MessagesTest : AbstractTest() {
@Test
fun `send message exception responses`() {
assertApiResponseException<MessageResponseException>(sendUrl, HttpMethod.POST) {
messagesClient.send(smsText {
client.send(smsText {
from(altNumber); to(toNumber); text(text)
})
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/kotlin/com/vonage/client/kt/NumberInsightTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.math.BigDecimal
import kotlin.test.*

class NumberInsightTest : AbstractTest() {
private val niClient = vonage.numberInsight
private val client = vonage.numberInsight
private val cnam = true
private val realTimeData = true
private val statusMessage = "Success"
Expand Down Expand Up @@ -230,48 +230,48 @@ class NumberInsightTest : AbstractTest() {
@Test
fun `basic insight required params`() {
mockInsight(InsightType.BASIC, false)
assertBasicResponse(niClient.basic(toNumber))
assertBasicResponse(client.basic(toNumber))
}

@Test
fun `basic insight all params`() {
mockInsight(InsightType.BASIC, true)
assertBasicResponse(niClient.basic(toNumber, countryCode))
assertBasicResponse(client.basic(toNumber, countryCode))
}

@Test
fun `standard insight required params`() {
mockInsight(InsightType.STANDARD, false)
assertStandardResponse(niClient.standard(toNumber))
assertStandardResponse(client.standard(toNumber))
}

@Test
fun `standard insight all params`() {
mockInsight(InsightType.STANDARD, true)
assertStandardResponse(niClient.standard(toNumber, countryCode, cnam))
assertStandardResponse(client.standard(toNumber, countryCode, cnam))
}

@Test
fun `advanced insight required params`() {
mockInsight(InsightType.ADVANCED, false)
assertAdvancedResponse(niClient.advanced(toNumber))
assertAdvancedResponse(client.advanced(toNumber))
}

@Test
fun `advanced insight all params`() {
mockInsight(InsightType.ADVANCED, true)
assertAdvancedResponse(niClient.advanced(toNumber, countryCode, cnam, realTimeData))
assertAdvancedResponse(client.advanced(toNumber, countryCode, cnam, realTimeData))
}

@Test
fun `advanced async insight required params`() {
mockInsight(InsightType.ADVANCED_ASYNC, false)
niClient.advancedAsync(toNumber, callbackUrl)
client.advancedAsync(toNumber, callbackUrl)
}

@Test
fun `advanced async insight all params`() {
mockInsight(InsightType.ADVANCED_ASYNC, true)
niClient.advancedAsync(toNumber, callbackUrl, countryCode, cnam)
client.advancedAsync(toNumber, callbackUrl, countryCode, cnam)
}
}
10 changes: 5 additions & 5 deletions src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.net.URLEncoder
import kotlin.test.*

class NumberVerificationTest : AbstractTest() {
private val nvClient = vonage.numberVerification
private val client = vonage.numberVerification
private val nvCheckUrl = "/camara/number-verification/v031/verify"
private val clientAuthUrl = "https://oidc.idp.vonage.com/oauth2/auth"
private val redirectUrl = "$exampleUrlBase/nv/redirect"
Expand Down Expand Up @@ -50,7 +50,7 @@ class NumberVerificationTest : AbstractTest() {
expectedResponseParams = if (result != null)
mapOf("devicePhoneNumberVerified" to result) else mapOf()
)
assertEquals(result ?: false, invocation(nvClient))
assertEquals(result ?: false, invocation(client))
}
}

Expand All @@ -62,10 +62,10 @@ class NumberVerificationTest : AbstractTest() {
URLEncoder.encode(redirectUrl, "UTF-8")
}&response_type=code"

assertEquals(URI.create(expectedUrlStr), nvClient.createVerificationUrl(toNumber, redirectUrl))
assertEquals(URI.create(expectedUrlStr), client.createVerificationUrl(toNumber, redirectUrl))

val expectedUrlWithState = URI.create("$expectedUrlStr&state=$state")
assertEquals(expectedUrlWithState, nvClient.createVerificationUrl(toNumber, redirectUrl, state))
assertEquals(expectedUrlWithState, client.createVerificationUrl(toNumber, redirectUrl, state))
}

@Test
Expand All @@ -84,7 +84,7 @@ class NumberVerificationTest : AbstractTest() {

@Test
fun `verify number relying on cached redirect url`() {
nvClient.createVerificationUrl(altNumber, redirectUrl)
client.createVerificationUrl(altNumber, redirectUrl)

assertVerifyNumber {
verifyNumberWithCode(toNumber, code)
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.vonage.client.auth.camara.FraudPreventionDetectionScope
import kotlin.test.*

class SimSwapTest : AbstractTest() {
private val simSwapClient = vonage.simSwap
private val client = vonage.simSwap
private val baseSimSwapUrl = "/camara/sim-swap/v040"
private val checkSimSwapUrl = "$baseSimSwapUrl/check"
private val retrieveSimSwapDateUrl = "$baseSimSwapUrl/retrieve-date"
Expand Down Expand Up @@ -66,7 +66,7 @@ class SimSwapTest : AbstractTest() {
expectedRequestParams = phoneNumberMap + mapOf("maxAge" to maxAge),
expectedResponseParams = if (result != null) mapOf("swapped" to result) else mapOf()
)
assertEquals(result == true, invocation(simSwapClient))
assertEquals(result == true, invocation(client))
}
}

Expand All @@ -78,7 +78,7 @@ class SimSwapTest : AbstractTest() {
expectedRequestParams = phoneNumberMap,
expectedResponseParams = if (includeResponse) mapOf("latestSimChange" to timestampStr) else mapOf()
)
assertEquals(if (includeResponse) timestamp else null, simSwapClient.retrieveSimSwapDate(simSwapNumber))
assertEquals(if (includeResponse) timestamp else null, client.retrieveSimSwapDate(simSwapNumber))
}

@Test
Expand Down
18 changes: 9 additions & 9 deletions src/test/kotlin/com/vonage/client/kt/SmsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.math.BigDecimal
import kotlin.test.*

class SmsTest : AbstractTest() {
private val smsClient = vonage.sms
private val client = vonage.sms
private val sendUrl = "/sms/json"
private val from = brand
private val accountRef = "customer1234"
Expand Down Expand Up @@ -70,22 +70,22 @@ class SmsTest : AbstractTest() {
assertEquals(network, first.network)
assertEquals(clientRef, first.clientRef)
assertEquals(accountRef, first.accountRef)
assertTrue(smsClient.wasSuccessfullySent(response))
assertTrue(client.wasSuccessfullySent(response))
}

private fun errorStatus(code: Int, text: String) = mapOf("status" to code, "error-text" to text)

@Test
fun `send regular text message success required parameters`() {
testSuccessSingleMessage(mapOf("from" to from, "to" to toNumber, "text" to text, "type" to "unicode")) {
smsClient.sendText(from, toNumber, text, unicode = true)
client.sendText(from, toNumber, text, unicode = true)
}
}

@Test
fun `send unicode text message success required parameters`() {
testSuccessSingleMessage(mapOf("from" to from, "to" to toNumber, "text" to text, "type" to "text")) {
smsClient.sendText(from, toNumber, text)
client.sendText(from, toNumber, text)
}
}

Expand All @@ -104,7 +104,7 @@ class SmsTest : AbstractTest() {
"entity-id" to entityId,
"content-id" to contentId
)) {
smsClient.sendText(from, toNumber, text,
client.sendText(from, toNumber, text,
unicode = false, statusReport = statusReport,
ttl = ttl, messageClass = Message.MessageClass.CLASS_1,
clientRef = clientRef, contentId = contentId, entityId = entityId,
Expand All @@ -119,7 +119,7 @@ class SmsTest : AbstractTest() {
"from" to from, "to" to toNumber, "type" to "binary",
"body" to textHexEncoded, "udh" to udhHex.lowercase()
)) {
smsClient.sendBinary(from, toNumber, text.encodeToByteArray(), udhBinary)
client.sendBinary(from, toNumber, text.encodeToByteArray(), udhBinary)
}
}

Expand All @@ -140,7 +140,7 @@ class SmsTest : AbstractTest() {
"entity-id" to entityId,
"content-id" to contentId
)) {
smsClient.sendBinary(from, toNumber, text.encodeToByteArray(), udh = udhBinary,
client.sendBinary(from, toNumber, text.encodeToByteArray(), udh = udhBinary,
protocolId = protocolId, statusReport = statusReport, ttl = ttl,
messageClass = Message.MessageClass.CLASS_2, clientRef = clientRef,
contentId = contentId, entityId = entityId, callbackUrl = moCallbackUrl
Expand Down Expand Up @@ -183,9 +183,9 @@ class SmsTest : AbstractTest() {
)
)
)
val response = smsClient.sendText(from, toNumber, text)
val response = client.sendText(from, toNumber, text)
assertNotNull(response)
assertFalse(smsClient.wasSuccessfullySent(response))
assertFalse(client.wasSuccessfullySent(response))

assertEquals(24, response.size)
var offset = 0
Expand Down
Loading

0 comments on commit 612b801

Please sign in to comment.