Skip to content

Commit

Permalink
Test nextWorkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 24, 2024
1 parent e2d7461 commit bde052a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.assertThrows
import java.net.URI
import java.util.*
import kotlin.test.assertEquals

abstract class AbstractTest {
Expand All @@ -21,6 +22,7 @@ abstract class AbstractTest {
private val apiKeySecretEncoded = "YTFiMmMzZDQ6MTIzNDU2Nzg5MGFiY2RlZg=="
protected val toNumber = "447712345689"
protected val altNumber = "447700900001"
protected val testUuid = UUID.fromString("aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab")

private val port = 8081
val wiremock: WireMockServer = WireMockServer(
Expand Down Expand Up @@ -60,7 +62,7 @@ abstract class AbstractTest {
JWT, API_KEY_SECRET_HEADER, API_KEY_SECRET_QUERY_PARAMS
}

protected fun baseMockRequest(
protected fun mockRequest(
httpMethod: HttpMethod,
expectedUrl: String,
contentType: ContentType? = null,
Expand Down Expand Up @@ -105,19 +107,17 @@ abstract class AbstractTest {
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)
mockRequest(HttpMethod.POST, expectedUrl,
contentType = if (expectedRequestParams != null) ContentType.APPLICATION_JSON else null,
accept = if (expectedResponseParams != null) ContentType.APPLICATION_JSON else null,
AuthType.JWT, expectedRequestParams
).mockReturn(status, expectedResponseParams)

protected fun mockJsonJwtPostRequest(expectedUrl: String,
expectedBodyParams: Map<String, Any>? = null): BuildingStep =
baseMockRequest(HttpMethod.POST, expectedUrl,
ContentType.APPLICATION_JSON, ContentType.APPLICATION_JSON,
AuthType.JWT, expectedBodyParams
)
protected fun mockDelete(expectedUrl: String, authType: AuthType? = null): ReturnsStep =
mockRequest(HttpMethod.DELETE, expectedUrl, authType = authType).mockReturn(204)

protected fun BuildingStep.mockJsonReturn(
protected fun BuildingStep.mockReturn(
status: Int? = null, expectedBody: Map<String, Any>? = null): ReturnsStep =
returns {
statusCode = if
Expand All @@ -141,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).mockJsonReturn(status, mapOf(
mockRequest(requestMethod, url).mockReturn(status, mapOf(
"type" to errorType, "title" to title,
"detail" to detail, "instance" to instance
))
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.test.assertNotNull
class MessagesTest : AbstractTest() {
private val messagesClient = vonageClient.messages
private val sendUrl = "/v1/messages"
private val messageUuid = UUID.fromString("aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab")
private val messageUuid = testUuid
private val mmsChannel = "mms"
private val whatsappChannel = "whatsapp"
private val viberChannel = "viber_service"
Expand Down Expand Up @@ -372,7 +372,6 @@ class MessagesTest : AbstractTest() {
val title2 = "Misc."
val product2 = UUID.randomUUID().toString()


val params = whatsappCustomBody(mapOf(
"type" to "interactive",
"interactive" to mapOf(
Expand Down
9 changes: 8 additions & 1 deletion src/test/kotlin/com/vonage/client/kt/VerifyTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vonage.client.kt

import com.vonage.client.common.HttpMethod
import org.junit.jupiter.api.Test
import java.net.URI
import java.util.UUID
Expand All @@ -26,7 +27,7 @@ class VerifyTest : AbstractTest() {
val appHash = "ABC123def45"
val toEmail = "[email protected]"
val fromEmail = "[email protected]"
val checkUrl = "https://api.nexmo.com/v2/verify/c11236f4-00bf-4b89-84ba-88b25df97315/silent-auth/redirect"
val checkUrl = "https://api.nexmo.com/v2/verify/$requestId/silent-auth/redirect"
val redirectUrl = "https://acme-app.com/sa/redirect"

mockJsonJwtPost(baseUrl,
Expand Down Expand Up @@ -98,4 +99,10 @@ class VerifyTest : AbstractTest() {
mockDelete("$baseUrl/$requestId")
verifyClient.cancelVerification(requestId)
}

@Test
fun `next workflow`() {
mockJsonJwtPost("$baseUrl/$requestId/next-workflow")
verifyClient.nextWorkflow(requestId)
}
}

0 comments on commit bde052a

Please sign in to comment.