Skip to content

Commit

Permalink
Test Verify.sendVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 24, 2024
1 parent c578098 commit 3f1a5fd
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/main/kotlin/com/vonage/client/kt/Verify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
91 changes: 91 additions & 0 deletions src/test/kotlin/com/vonage/client/kt/VerifyTest.kt
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
val fromEmail = "[email protected]"
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)
}

}

0 comments on commit 3f1a5fd

Please sign in to comment.