diff --git a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt index ecf00d9..f9763ed 100644 --- a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt @@ -101,21 +101,23 @@ abstract class AbstractTest { else -> throw IllegalArgumentException("Unhandled HTTP method: $httpMethod") }) - protected fun mockJsonJwtPostRequestResponse(expectedUrl: String, - expectedRequestParams: Map? = null, - status: Int = 200, - expectedResponseParams: Map? = null) = - mockJsonJwtPostRequest(expectedUrl, expectedRequestParams) - .baseMockJsonReturn(status, expectedResponseParams) + protected fun mockJsonJwtPost(expectedUrl: String, + expectedRequestParams: Map? = null, + status: Int = 200, + expectedResponseParams: Map? = 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? = null) = + expectedBodyParams: Map? = 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? = null): ReturnsStep = returns { statusCode = if @@ -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 )) diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index 1d7b8c4..ef73d7d 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -31,7 +31,7 @@ class MessagesTest : AbstractTest() { private fun testSend(expectedBodyParams: Map, 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)) } diff --git a/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt b/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt index 946a983..9b63868 100644 --- a/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VerifyTest.kt @@ -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`() { @@ -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, @@ -93,4 +93,9 @@ class VerifyTest : AbstractTest() { assertEquals(URI.create(checkUrl), response.checkUrl) } + @Test + fun `cancel verification`() { + mockDelete("$baseUrl/$requestId") + verifyClient.cancelVerification(requestId) + } } \ No newline at end of file