Skip to content

Commit

Permalink
Test cancelVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 24, 2024
1 parent 3f1a5fd commit e2d7461
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,23 @@ abstract class AbstractTest {
else -> throw IllegalArgumentException("Unhandled HTTP method: $httpMethod")
})

protected fun mockJsonJwtPostRequestResponse(expectedUrl: String,
expectedRequestParams: Map<String, Any>? = null,
status: Int = 200,
expectedResponseParams: Map<String, Any>? = null) =
mockJsonJwtPostRequest(expectedUrl, expectedRequestParams)
.baseMockJsonReturn(status, expectedResponseParams)
protected fun mockJsonJwtPost(expectedUrl: String,
expectedRequestParams: Map<String, Any>? = null,
status: Int = 200,
expectedResponseParams: Map<String, Any>? = null) =
mockJsonJwtPostRequest(expectedUrl, expectedRequestParams).mockJsonReturn(status, expectedResponseParams)

protected fun mockDelete(expectedUrl: String, authType: AuthType? = null): ReturnsStep =
baseMockRequest(HttpMethod.DELETE, expectedUrl, authType = authType).mockJsonReturn(204)

protected fun mockJsonJwtPostRequest(expectedUrl: String,
expectedBodyParams: Map<String, Any>? = null) =
expectedBodyParams: Map<String, Any>? = null): BuildingStep =
baseMockRequest(HttpMethod.POST, expectedUrl,
ContentType.APPLICATION_JSON, ContentType.APPLICATION_JSON,
AuthType.JWT, expectedBodyParams
)

protected fun BuildingStep.baseMockJsonReturn(
protected fun BuildingStep.mockJsonReturn(
status: Int? = null, expectedBody: Map<String, Any>? = null): ReturnsStep =
returns {
statusCode = if
Expand All @@ -139,7 +141,7 @@ abstract class AbstractTest {
url: String, requestMethod: HttpMethod, actualCall: () -> Unit, status: Int,
errorType: String, title: String, detail: String, instance: String): E {

baseMockRequest(requestMethod, url).baseMockJsonReturn(status, mapOf(
baseMockRequest(requestMethod, url).mockJsonReturn(status, mapOf(
"type" to errorType, "title" to title,
"detail" to detail, "instance" to instance
))
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MessagesTest : AbstractTest() {


private fun testSend(expectedBodyParams: Map<String, Any>, req: MessageRequest) {
mockJsonJwtPostRequestResponse(sendUrl, expectedBodyParams, 202, mapOf("message_uuid" to messageUuid))
mockJsonJwtPost(sendUrl, expectedBodyParams, 202, mapOf("message_uuid" to messageUuid))
assertEquals(messageUuid, messagesClient.send(req))
}

Expand Down
9 changes: 7 additions & 2 deletions src/test/kotlin/com/vonage/client/kt/VerifyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlin.test.assertNotNull
class VerifyTest : AbstractTest() {
private val verifyClient = vonageClient.verify
private val baseUrl = "/v2/verify"
private val requestId = "c11236f4-00bf-4b89-84ba-88b25df97315"

@Test
fun `send verification all workflows and parameters`() {
Expand All @@ -25,11 +26,10 @@ class VerifyTest : AbstractTest() {
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,
mockJsonJwtPost(baseUrl,
expectedRequestParams = mapOf(
"brand" to brand,
"client_ref" to clientRef,
Expand Down Expand Up @@ -93,4 +93,9 @@ class VerifyTest : AbstractTest() {
assertEquals(URI.create(checkUrl), response.checkUrl)
}

@Test
fun `cancel verification`() {
mockDelete("$baseUrl/$requestId")
verifyClient.cancelVerification(requestId)
}
}

0 comments on commit e2d7461

Please sign in to comment.