From b5f2800ab935ed6aaaea2ba176798065b5060fe3 Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Wed, 26 Jun 2024 11:17:41 +0100 Subject: [PATCH] feat: Messages sandbox --- CHANGELOG.md | 6 ++++++ src/main/kotlin/com/vonage/client/kt/Messages.kt | 8 +++++--- src/test/kotlin/com/vonage/client/kt/MessagesTest.kt | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf48b8f..39fdf8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.0] - 2024-07-?? + +### Added +- Sandbox support in Messages + + ## [0.1.0] - 2024-06-25 Initial version. diff --git a/src/main/kotlin/com/vonage/client/kt/Messages.kt b/src/main/kotlin/com/vonage/client/kt/Messages.kt index 0db2b10..18a75d5 100644 --- a/src/main/kotlin/com/vonage/client/kt/Messages.kt +++ b/src/main/kotlin/com/vonage/client/kt/Messages.kt @@ -9,9 +9,11 @@ import com.vonage.client.messages.viber.* import java.util.UUID class Messages(private val client: MessagesClient) { - fun send(message: MessageRequest): UUID { - return client.sendMessage(message).messageUuid - } + fun send(message: MessageRequest): UUID = + client.useRegularEndpoint().sendMessage(message).messageUuid + + fun sendSandbox(message: MessageRequest): UUID = + client.useSandboxEndpoint().sendMessage(message).messageUuid } fun parseInboundMessage(json: String) : InboundMessage { diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index 02756cc..9f05f3f 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -16,6 +16,7 @@ import kotlin.test.assertNotNull class MessagesTest : AbstractTest() { private val messagesClient = vonageClient.messages private val sendUrl = "/v1/messages" + private val sandboxUrl = "https://messages-sandbox.nexmo.com$sendUrl" private val messageUuid = testUuid private val mmsChannel = "mms" private val whatsappChannel = "whatsapp" @@ -31,7 +32,13 @@ class MessagesTest : AbstractTest() { private fun testSend(expectedBodyParams: Map, req: MessageRequest) { - mockJsonJwtPost(sendUrl, expectedBodyParams, 202, mapOf("message_uuid" to messageUuid)) + val status = 202 + val expectedResponseParams = mapOf("message_uuid" to messageUuid) + + mockJsonJwtPost(sendUrl, expectedBodyParams, status, expectedResponseParams) + assertEquals(messageUuid, messagesClient.send(req)) + + mockJsonJwtPost(sandboxUrl, expectedBodyParams, status, expectedResponseParams) assertEquals(messageUuid, messagesClient.send(req)) }