diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab6a184..4008766 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt index aa3ed40..746cae3 100644 --- a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt @@ -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 { diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index 0498218..93d6174 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -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 = mapOf( - "message_type" to "text", - "text" to text, - "to" to toNumber, - "from" to fromNumber, - "channel" to channel - ) - - fun mockResponse(expectedBodyParams: Map) { + private fun mockResponse(expectedBodyParams: Map) { wiremock.post { url equalTo "/v1/messages" headers contains "User-Agent" like "vonage-java-sdk.*" @@ -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, req: MessageRequest) { + mockResponse(expectedBodyParams) + assertEquals(messageUuid, messagesClient.send(req)) + } + + private fun expectedTextBody(channel: String): Map = 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) }) } } \ No newline at end of file