diff --git a/src/main/kotlin/com/vonage/client/kt/Verify.kt b/src/main/kotlin/com/vonage/client/kt/Verify.kt index f8d8a2f..d1cf5b5 100644 --- a/src/main/kotlin/com/vonage/client/kt/Verify.kt +++ b/src/main/kotlin/com/vonage/client/kt/Verify.kt @@ -8,24 +8,16 @@ class Verify(private val verify2Client: Verify2Client) { fun sendVerification( brand: String = "Vonage", init: VerificationRequest.Builder.() -> Unit - ): UUID { + ): VerificationResponse = verify2Client.sendVerification( + VerificationRequest.builder().brand(brand).apply(init).build() + ) - return verify2Client.sendVerification( - VerificationRequest.builder().brand(brand).apply(init).build() - ).requestId - } - - fun cancelVerification(requestId: String) { - verify2Client.cancelVerification(UUID.fromString(requestId)) - } + fun cancelVerification(requestId: String) = verify2Client.cancelVerification(UUID.fromString(requestId)) - fun nextWorkflow(requestId: String) { - verify2Client.nextWorkflow(UUID.fromString(requestId)) - } + fun nextWorkflow(requestId: String) = verify2Client.nextWorkflow(UUID.fromString(requestId)) - fun checkVerificationCode(requestId: String, code: String) { + fun checkVerificationCode(requestId: String, code: String) = verify2Client.checkVerificationCode(UUID.fromString(requestId), code) - } fun isValidVerificationCode(requestId: String, code: String): Boolean { try { @@ -41,29 +33,22 @@ class Verify(private val verify2Client: Verify2Client) { } } -fun VerificationRequest.Builder.silentAuth(number: String): VerificationRequest.Builder { - return this.addWorkflow(SilentAuthWorkflow(number)) -} +fun VerificationRequest.Builder.silentAuth( + number: String, sandbox: Boolean = false, redirectUrl: String? = null): VerificationRequest.Builder = + addWorkflow(SilentAuthWorkflow(number, sandbox, redirectUrl)) fun VerificationRequest.Builder.sms( - number: String, - init: SmsWorkflow.Builder.() -> Unit = {} -): VerificationRequest.Builder { - return this.addWorkflow(SmsWorkflow.builder(number).apply(init).build()) -} + number: String, init: SmsWorkflow.Builder.() -> Unit = {}): VerificationRequest.Builder = + addWorkflow(SmsWorkflow.builder(number).apply(init).build()) -fun VerificationRequest.Builder.voice(number: String): VerificationRequest.Builder { - return this.addWorkflow(VoiceWorkflow(number)) -} +fun VerificationRequest.Builder.voice(number: String): VerificationRequest.Builder = + addWorkflow(VoiceWorkflow(number)) -fun VerificationRequest.Builder.email(to: String, from: String? = null): VerificationRequest.Builder { - return this.addWorkflow(EmailWorkflow(to, from)) -} +fun VerificationRequest.Builder.email(to: String, from: String? = null): VerificationRequest.Builder = + addWorkflow(EmailWorkflow(to, from)) -fun VerificationRequest.Builder.whatsapp(to: String, from: String): VerificationRequest.Builder { - return this.addWorkflow(WhatsappWorkflow(to, from)) -} +fun VerificationRequest.Builder.whatsapp(to: String, from: String): VerificationRequest.Builder = + addWorkflow(WhatsappWorkflow(to, from)) -fun VerificationRequest.Builder.whatsappCodeless(to: String, from: String): VerificationRequest.Builder { - return this.addWorkflow(WhatsappCodelessWorkflow(to, from)) -} +fun VerificationRequest.Builder.whatsappCodeless(to: String, from: String): VerificationRequest.Builder = + addWorkflow(WhatsappCodelessWorkflow(to, from)) diff --git a/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt b/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt index fb595ba..946a983 100644 --- a/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt @@ -1,5 +1,96 @@ package com.vonage.client.kt +import org.junit.jupiter.api.Test +import java.net.URI +import java.util.UUID +import kotlin.test.assertEquals +import kotlin.test.assertNotNull + class VerifyTest : AbstractTest() { + private val verifyClient = vonageClient.verify + private val baseUrl = "/v2/verify" + + @Test + fun `send verification all workflows and parameters`() { + val brand = "Nexmo KT" + val clientRef = "my-personal-reference" + val timeout = 60 + val fraudCheck = false + val sandbox = true + val codeLength = 5 + val locale = "ja-jp" + val whatsappNumber = "447700400080" + val entityId = "1101407360000017170" + val contentId = "1107158078772563946" + val appHash = "ABC123def45" + val toEmail = "alice@example.com" + val fromEmail = "bob@example.org" + val requestId = "c11236f4-00bf-4b89-84ba-88b25df97315" + val checkUrl = "https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315/silent-auth/redirect" + val redirectUrl = "https://acme-app.com/sa/redirect" + + mockJsonJwtPostRequestResponse(baseUrl, + expectedRequestParams = mapOf( + "brand" to brand, + "client_ref" to clientRef, + "channel_timeout" to timeout, + "code_length" to codeLength, + "locale" to "ja-jp", + "fraud_check" to fraudCheck, + "workflow" to listOf( + mapOf( + "channel" to "silent_auth", + "to" to toNumber, + "sandbox" to sandbox, + "redirect_url" to redirectUrl + ), + mapOf( + "channel" to "voice", + "to" to altNumber + ), + mapOf( + "channel" to "sms", + "to" to toNumber, + "from" to altNumber, + "content_id" to contentId, + "entity_id" to entityId, + "app_hash" to appHash + ), + mapOf( + "channel" to "email", + "to" to toEmail, + "from" to fromEmail + ), + mapOf( + "channel" to "whatsapp", + "to" to altNumber, + "from" to whatsappNumber + ), + mapOf( + "channel" to "whatsapp_interactive", + "to" to toNumber, + "from" to whatsappNumber + ) + ) + ), + expectedResponseParams = mapOf( + "request_id" to requestId, + "check_url" to checkUrl + ) + ) + + val response = verifyClient.sendVerification { + brand(brand); clientRef(clientRef); channelTimeout(timeout) + fraudCheck(fraudCheck); codeLength(codeLength); locale(locale) + silentAuth(toNumber, sandbox, redirectUrl); voice(altNumber); sms(toNumber) { + entityId(entityId); contentId(contentId); appHash(appHash); from(altNumber) + }; email(toEmail, fromEmail) + whatsapp(altNumber, whatsappNumber); whatsappCodeless(toNumber, whatsappNumber) + } + + assertNotNull(response) + assertEquals(UUID.fromString(requestId), response.requestId) + assertEquals(URI.create(checkUrl), response.checkUrl) + } } \ No newline at end of file