diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4008766..98a1b80 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,4 @@ jobs: java-version: ${{ matrix.java }} 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 + run: mvn --batch-mode clean verify \ No newline at end of file diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index 93d6174..2cc47ea 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -1,5 +1,6 @@ package com.vonage.client.kt +import com.fasterxml.jackson.databind.ObjectMapper import com.marcinziolo.kotlin.wiremock.* import com.vonage.client.messages.MessageRequest import org.junit.jupiter.api.Test @@ -8,21 +9,26 @@ import kotlin.test.assertEquals class MessagesTest : AbstractTest() { val messagesClient = vonageClient.messages + val messageUuid = UUID.fromString("aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab") + val mmsChannel = "mms" + val whatsappChannel = "whatsapp" + val viberChannel = "viber_service" + val messengerChannel = "messenger" val fromNumber = "447700900001" val toNumber = "447712345689" val text = "Hello, World!" - val messageUuid = UUID.fromString("aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab") + val caption = "Additional text to accompany the media" + val imageUrl = "https://example.com/image.jpg" + val captionMap = mutableMapOf("caption" to caption) - private fun mockResponse(expectedBodyParams: Map) { + private fun mockResponse(expectedBodyParams: Map) { wiremock.post { url equalTo "/v1/messages" headers contains "User-Agent" like "vonage-java-sdk.*" headers contains "Authorization" like "Bearer eyJ.+" headers contains "Content-Type" equalTo "application/json" headers contains "Accept" equalTo "application/json" - for (entry in expectedBodyParams.entries) { - body contains entry.key equalTo entry.value - } + body equalTo ObjectMapper().writeValueAsString(expectedBodyParams) } returns { header = "Content-Type" to "application/json" statusCode = 202 @@ -34,44 +40,89 @@ class MessagesTest : AbstractTest() { } } - private fun testSend(expectedBodyParams: Map, req: MessageRequest) { + 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 - ) + private fun baseBody(messageType: String, channel: String): Map = + mapOf( + "message_type" to messageType, + "to" to toNumber, + "from" to fromNumber, + "channel" to channel + ) + + private fun textBody(channel: String): Map = + baseBody("text", channel) + mapOf("text" to text) + + private fun mediaBody(channel: String, messageType: String, url: String, additionalParams: Map? = null): Map = + baseBody(messageType, channel) + mapOf(messageType to mapOf("url" to url) + (additionalParams ?: mapOf())) + + private fun imageBody(channel: String, additionalParams : Map? = null): Map = + mediaBody(channel, "image", imageUrl, additionalParams) @Test fun `send SMS`() { - testSend(expectedTextBody("sms"), smsText { + testSend(textBody("sms"), smsText { from(fromNumber); to(toNumber); text(text) }) } @Test fun `send WhatsApp text`() { - testSend(expectedTextBody("whatsapp"), whatsappText { + testSend(textBody(whatsappChannel), whatsappText { from(fromNumber); to(toNumber); text(text) }) } @Test fun `send Viber text`() { - testSend(expectedTextBody("viber_service"), viberText { + testSend(textBody(viberChannel), viberText { from(fromNumber); to(toNumber); text(text) }) } @Test fun `send Messenger text`() { - testSend(expectedTextBody("messenger"), messengerText { + testSend(textBody(messengerChannel), messengerText { from(fromNumber); to(toNumber); text(text) }) } + + @Test + fun `send MMS vCard`() { + val vcardUrl = "https://example.com/conatact.vcf" + testSend(mediaBody(mmsChannel, "vcard", vcardUrl, captionMap), mmsVcard { + from(fromNumber); to(toNumber); url(vcardUrl); caption(caption) + }) + } + + @Test + fun `send MMS image`() { + testSend(imageBody(mmsChannel, captionMap), mmsImage { + from(fromNumber); to(toNumber); url(imageUrl); caption(caption) + }) + } + + @Test + fun `send WhatsApp image`() { + testSend(imageBody(whatsappChannel, captionMap), whatsappImage { + from(fromNumber); to(toNumber); url(imageUrl); caption(caption) + }) + } + + @Test + fun `send Viber image`() { + testSend(imageBody(viberChannel), viberImage { + from(fromNumber); to(toNumber); url(imageUrl) + }) + } + + @Test + fun `send Messenger image`() { + testSend(imageBody(messengerChannel), messengerImage { + from(fromNumber); to(toNumber); url(imageUrl) + }) + } } \ No newline at end of file