Skip to content

Commit 60874df

Browse files
authored
Merge pull request #124 from olimpias/fallback-support
Add unit test for sendMessage in conversation tests
2 parents f48be62 + a92a267 commit 60874df

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

api/src/test/java/com/messagebird/ConversationMessagesTest.java

+26
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ConversationMessagesTest {
2222
private static final String JSON_CONVERSATION_MESSAGE_LOCATION = "{\"id\": \"mesid\",\"conversationId\": \"convid\",\"channelId\": \"chanid\",\"status\": \"received\",\"type\": \"location\",\"direction\": \"received\",\"content\": {\"location\": { \"latitude\": 52.344263, \"longitude\": 4.911627 } },\"createdDatetime\": \"2018-08-29T11:49:16Z\",\"updatedDatetime\": \"2018-08-29T11:49:16Z\"}";
2323
private static final String JSON_CONVERSATION_MESSAGE_TEXT = "{\"id\": \"mesid\",\"conversationId\": \"convid\",\"channelId\": \"chanid\",\"status\": \"received\",\"type\": \"text\",\"direction\": \"received\",\"content\": {\"text\": \"Hello\"},\"createdDatetime\": \"2018-08-29T11:49:16Z\",\"updatedDatetime\": \"2018-08-29T11:49:16Z\"}";
2424
private static final String JSON_CONVERSATION_MESSAGE_VIDEO = "{\"id\": \"mesid\",\"conversationId\": \"convid\",\"channelId\": \"chanid\",\"status\": \"received\",\"type\": \"video\",\"direction\": \"received\",\"content\": {\"video\": { \"url\": \"https://example.com/video.mp4\" } },\"createdDatetime\": \"2018-08-29T11:49:16Z\",\"updatedDatetime\": \"2018-08-29T11:49:16Z\"}";
25+
private static final String JSON_CONVERSATION_SEND_MESSAGE_RESPONSE = "{\"id\":\"mesid\",\"status\":\"accepted\",\"fallback\":{\"id\":\"mesid\"}}";
2526

2627
/**
2728
* Epsilon to use when checking two latitudes or longitudes for equality.
@@ -66,6 +67,31 @@ public void testSendConversationMessage() throws GeneralException, UnauthorizedE
6667
assertEquals(ConversationContentType.VIDEO, conversationMessage.getType());
6768
}
6869

70+
@Test
71+
public void testSendMessage() throws GeneralException, UnauthorizedException {
72+
ConversationContent conversationContent = new ConversationContent();
73+
conversationContent.setText("test");
74+
75+
ConversationSendRequest sendRequest = new ConversationSendRequest();
76+
sendRequest.setFrom("aChannelIdentifier");
77+
sendRequest.setType(ConversationContentType.TEXT);
78+
sendRequest.setContent(conversationContent);
79+
sendRequest.setReportUrl("https://example.com/reportUrl");
80+
81+
MessageBirdService messageBirdService = SpyService
82+
.expects("POST", "send", sendRequest)
83+
.withConversationsAPIBaseURL()
84+
.andReturns(new APIResponse(JSON_CONVERSATION_SEND_MESSAGE_RESPONSE));
85+
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);
86+
87+
ConversationSendResponse conversationMessage
88+
= messageBirdClient.sendMessage(sendRequest);
89+
90+
assertEquals("mesid", conversationMessage.getId());
91+
assertEquals("accepted", conversationMessage.getStatus());
92+
assertEquals("mesid", conversationMessage.getFallback().getId());
93+
}
94+
6995
@Test
7096
public void testViewConversationMessageAudio() throws GeneralException, NotFoundException, UnauthorizedException {
7197
MessageBirdService messageBirdService = SpyService

0 commit comments

Comments
 (0)