diff --git a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt index ff3488a..b9238cc 100644 --- a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt @@ -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 diff --git a/src/test/kotlin/com/vonage/client/kt/AccountTest.kt b/src/test/kotlin/com/vonage/client/kt/AccountTest.kt index 378a8c8..1914763 100644 --- a/src/test/kotlin/com/vonage/client/kt/AccountTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AccountTest.kt @@ -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" @@ -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, @@ -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) @@ -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) @@ -172,7 +172,7 @@ class AccountTest : AbstractTest() { status = errorCode, authType = authType, expectedResponseParams = errorResponse ) - assertThrows { account.getBalance() } + assertThrows { client.getBalance() } } @Test @@ -186,7 +186,7 @@ class AccountTest : AbstractTest() { "error-code-label" to "success" ) ) - account.topUp(trx) + client.topUp(trx) } @Test @@ -198,7 +198,7 @@ class AccountTest : AbstractTest() { expectedResponseParams = errorResponse ) - assertThrows { account.topUp(trx) } + assertThrows { client.topUp(trx) } } @Test diff --git a/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt b/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt index 00a9a8e..eb5d98a 100644 --- a/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt @@ -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" @@ -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) } } @@ -316,7 +316,7 @@ class ApplicationTest : AbstractTest() { expectedRequestParams = advancedApplicationRequest, expectedResponseParams = fullApplicationResponse ) - assertEqualsFullApplication(ac.create { + assertEqualsFullApplication(client.create { name(name) publicKey(publicKey) voice { @@ -369,7 +369,7 @@ class ApplicationTest : AbstractTest() { }) assert401ApiResponseException(baseUrl, HttpMethod.POST) { - ac.create { name(name) } + client.create { name(name) } } } } \ No newline at end of file diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index 50cb21d..76c1321 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -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" @@ -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 = @@ -84,7 +83,7 @@ class MessagesTest : AbstractTest() { @Test fun `send message exception responses`() { assertApiResponseException(sendUrl, HttpMethod.POST) { - messagesClient.send(smsText { + client.send(smsText { from(altNumber); to(toNumber); text(text) }) } diff --git a/src/test/kotlin/com/vonage/client/kt/NumberInsightTest.kt b/src/test/kotlin/com/vonage/client/kt/NumberInsightTest.kt index 7841f09..a1e828d 100644 --- a/src/test/kotlin/com/vonage/client/kt/NumberInsightTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/NumberInsightTest.kt @@ -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" @@ -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) } } \ No newline at end of file diff --git a/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt b/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt index 7ed0e7f..2b486ff 100644 --- a/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt @@ -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" @@ -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)) } } @@ -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 @@ -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) diff --git a/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt b/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt index 2d651a0..55a9da4 100644 --- a/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt @@ -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" @@ -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)) } } @@ -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 diff --git a/src/test/kotlin/com/vonage/client/kt/SmsTest.kt b/src/test/kotlin/com/vonage/client/kt/SmsTest.kt index 04c9514..01fb1d8 100644 --- a/src/test/kotlin/com/vonage/client/kt/SmsTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/SmsTest.kt @@ -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" @@ -70,7 +70,7 @@ 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) @@ -78,14 +78,14 @@ class SmsTest : AbstractTest() { @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) } } @@ -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, @@ -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) } } @@ -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 @@ -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 diff --git a/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt b/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt index aa7adbc..168e3c5 100644 --- a/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt @@ -21,9 +21,9 @@ import java.util.* import kotlin.test.* class VerifyLegacyTest : AbstractTest() { - private val verifyClient = vonage.verifyLegacy + private val client = vonage.verifyLegacy private val requestId = "abcdef0123456789abcdef0123456789" - private val existingRequest = verifyClient.request(requestId) + private val existingRequest = client.request(requestId) private val eventId = "0A00000012345678" private val accountId = "abcdef01" private val payee = "Acme Inc" @@ -45,11 +45,11 @@ class VerifyLegacyTest : AbstractTest() { "request_id" to requestId, "status" to "0" )) - val successParsed = invocation(verifyClient) + val successParsed = invocation(client) assertNotNull(successParsed) assertEquals(requestId, successParsed.requestId) assertEquals(VerifyStatus.OK, successParsed.status) - assertEquals(existingRequest, verifyClient.request(successParsed)) + assertEquals(existingRequest, client.request(successParsed)) val errorText = "Your request is incomplete and missing the mandatory parameter `number`" mockPostQueryParams(expectedUrl, params, expectedResponseParams = mapOf( @@ -58,7 +58,7 @@ class VerifyLegacyTest : AbstractTest() { "error_text" to errorText, "network" to networkCode )) - val failureParsed = invocation(verifyClient) + val failureParsed = invocation(client) assertNotNull(failureParsed) assertEquals(requestId, failureParsed.requestId) assertEquals(VerifyStatus.MISSING_PARAMS, failureParsed.status) @@ -137,7 +137,7 @@ class VerifyLegacyTest : AbstractTest() { ) ) ) - val response = if (single) existingRequest.search() else verifyClient.search(*requestIds) + val response = if (single) existingRequest.search() else client.search(*requestIds) assertNotNull(response) assertNull(response.errorText) assertEquals(3, response.verificationRequests.size) @@ -162,7 +162,7 @@ class VerifyLegacyTest : AbstractTest() { @Test fun `existing request hashCode is based on the requestId`() { assertEquals(requestId.hashCode(), existingRequest.hashCode()) - assertEquals(existingRequest, verifyClient.request(requestId)) + assertEquals(existingRequest, client.request(requestId)) assertEquals(existingRequest, existingRequest) assertFalse(existingRequest.equals(requestId)) } diff --git a/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt b/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt index 04c4dd2..401a3cb 100644 --- a/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt @@ -23,12 +23,12 @@ import java.util.UUID import kotlin.test.* class VerifyTest : AbstractTest() { - private val verifyClient = vonage.verify + private val client = vonage.verify private val baseUrl = "/v2/verify" private val requestIdStr = "c11236f4-00bf-4b89-84ba-88b25df97315" private val requestId = UUID.fromString(requestIdStr) private val requestIdUrl = "$baseUrl/$requestIdStr" - private val existingRequest = verifyClient.request(requestIdStr) + private val existingRequest = client.request(requestIdStr) private val timeout = 60 private val fraudCheck = false private val sandbox = true @@ -80,7 +80,7 @@ class VerifyTest : AbstractTest() { if (channel == Channel.SILENT_AUTH) mapOf("check_url" to checkUrl) else mapOf() ) - val response = verifyClient.sendVerification(brand) { + val response = client.sendVerification(brand) { when (channel) { Channel.VOICE -> voice(toNumber) Channel.SMS -> sms(toNumber) @@ -154,7 +154,7 @@ class VerifyTest : AbstractTest() { status = 202 ) - val response = verifyClient.sendVerification { + val response = client.sendVerification { brand(brand); clientRef(clientRef); channelTimeout(timeout) fraudCheck(fraudCheck); codeLength(codeLength); locale(locale) silentAuth(toNumber, sandbox, redirectUrl); voice(altNumber); sms(toNumber) { diff --git a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt index d020586..d833bb9 100644 --- a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt @@ -204,7 +204,7 @@ class VoiceTest : AbstractTest() { ) ) - val callEvent = this@VoiceTest.client.createCall(call) + val callEvent = client.createCall(call) assertNotNull(callEvent) assertEquals(callIdStr, callEvent.uuid) assertEquals(callStatus, callEvent.status) @@ -392,7 +392,7 @@ class VoiceTest : AbstractTest() { "conversation_uuid" to conversationId ), expectedResponseParams = listCallsResponse) - val callsPage = this@VoiceTest.client.listCalls { + val callsPage = client.listCalls { status(CallStatus.UNANSWERED) dateStart(startTimeStr); dateEnd(endTimeStr) pageSize(pageSize); recordIndex(recordIndex) @@ -405,7 +405,7 @@ class VoiceTest : AbstractTest() { @Test fun `list calls no filter`() { mockGet(callsBaseUrl, expectedResponseParams = listCallsResponse) - assertEqualsSampleCallsPage(this@VoiceTest.client.listCalls()) + assertEqualsSampleCallsPage(client.listCalls()) } @Test diff --git a/src/test/kotlin/com/vonage/client/kt/VonageTest.kt b/src/test/kotlin/com/vonage/client/kt/VonageTest.kt index c07797d..c991ce7 100644 --- a/src/test/kotlin/com/vonage/client/kt/VonageTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VonageTest.kt @@ -15,14 +15,13 @@ */ package com.vonage.client.kt -import org.junit.jupiter.api.Test import kotlin.test.* class VonageTest { @Test - fun `auth from env`() { - val vonage = Vonage { authFromEnv() } - assertNotNull(vonage) + fun `live testing placeholder`() { + val client = Vonage { authFromEnv() } + } } \ No newline at end of file