Skip to content

Commit

Permalink
Test text message all channels
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 20, 2024
1 parent 3f18d9e commit e796c2f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ jobs:
cache: maven
- name: Compile with Maven
run: mvn --batch-mode clean verify
- name: Run Codecov
uses: codecov/codecov-action@v4
2 changes: 1 addition & 1 deletion src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.junit.jupiter.api.BeforeEach
abstract class AbstractTest {
val port = 8081
val wiremock: WireMockServer = WireMockServer(
options().port(port).notifier(ConsoleNotifier(true))
options().port(port).notifier(ConsoleNotifier(false))
)

val vonageClient = Vonage {
Expand Down
57 changes: 42 additions & 15 deletions src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package com.vonage.client.kt

import com.marcinziolo.kotlin.wiremock.*
import com.vonage.client.messages.MessageRequest
import org.junit.jupiter.api.Test
import java.util.*
import kotlin.test.assertEquals

class MessagesTest : AbstractTest() {
val messagesClient = vonageClient.messages
val fromNumber = "447700900001"
val toNumber = "447712345689"
val text = "Hello, World!"
val messageUuid = UUID.fromString("aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab")

fun expectedTextBody(channel: String): Map<String, String> = mapOf(
"message_type" to "text",
"text" to text,
"to" to toNumber,
"from" to fromNumber,
"channel" to channel
)

fun mockResponse(expectedBodyParams: Map<String, String>) {
private fun mockResponse(expectedBodyParams: Map<String, String>) {
wiremock.post {
url equalTo "/v1/messages"
headers contains "User-Agent" like "vonage-java-sdk.*"
Expand All @@ -32,19 +28,50 @@ class MessagesTest : AbstractTest() {
statusCode = 202
body = """
{
"message_uuid": "aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
"message_uuid": "$messageUuid"
}
"""
}
}

private fun testSend(expectedBodyParams: Map<String, String>, req: MessageRequest) {
mockResponse(expectedBodyParams)
assertEquals(messageUuid, messagesClient.send(req))
}

private fun expectedTextBody(channel: String): Map<String, String> = mapOf(
"message_type" to "text",
"text" to text,
"to" to toNumber,
"from" to fromNumber,
"channel" to channel
)

@Test
fun `send SMS`() {
mockResponse(expectedTextBody("sms"))
messagesClient.send(smsText {
from(fromNumber)
to(toNumber)
text(text)
testSend(expectedTextBody("sms"), smsText {
from(fromNumber); to(toNumber); text(text)
})
}

@Test
fun `send WhatsApp text`() {
testSend(expectedTextBody("whatsapp"), whatsappText {
from(fromNumber); to(toNumber); text(text)
})
}

@Test
fun `send Viber text`() {
testSend(expectedTextBody("viber_service"), viberText {
from(fromNumber); to(toNumber); text(text)
})
}

@Test
fun `send Messenger text`() {
testSend(expectedTextBody("messenger"), messengerText {
from(fromNumber); to(toNumber); text(text)
})
}
}

0 comments on commit e796c2f

Please sign in to comment.