Skip to content

Commit f8a435f

Browse files
Added tests
1 parent c57b160 commit f8a435f

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package org.zendesk.client.v2.model;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertThrows;
5+
6+
import com.fasterxml.jackson.core.JsonProcessingException;
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
9+
import com.fasterxml.jackson.databind.node.ObjectNode;
10+
import java.util.function.Function;
11+
import org.jetbrains.annotations.Nullable;
12+
import org.junit.Test;
13+
import org.zendesk.client.v2.Zendesk;
14+
import org.zendesk.client.v2.model.comments.VoiceComment;
15+
16+
public class CommentTest {
17+
18+
private static final long COMMENT_ID = 123L;
19+
private static final String COMMENT_BODY = "Foo";
20+
private static final String COMMENT_VOICE_URL = "http://yourdomain.com/recordings/1.mp3";
21+
22+
private static final ObjectMapper MAPPER = Zendesk.createMapper(Function.identity());
23+
24+
@Test
25+
public void defaultType() throws JsonProcessingException {
26+
String json = createCommentJson(null);
27+
Comment comment = parseJson(json);
28+
assertEquals(Comment.class, comment.getClass());
29+
assertEquals(Long.valueOf(COMMENT_ID), comment.getId());
30+
assertEquals(COMMENT_BODY, comment.getBody());
31+
}
32+
33+
@Test
34+
public void explicitTypeComment() throws JsonProcessingException {
35+
String json = createCommentJson("Comment");
36+
Comment comment = parseJson(json);
37+
assertEquals(Comment.class, comment.getClass());
38+
assertEquals(Long.valueOf(COMMENT_ID), comment.getId());
39+
assertEquals(COMMENT_BODY, comment.getBody());
40+
}
41+
42+
@Test
43+
public void explicitTypeVoiceComment() throws JsonProcessingException {
44+
String json = createCommentJson("VoiceComment");
45+
Comment comment = parseJson(json);
46+
assertEquals(VoiceComment.class, comment.getClass());
47+
48+
VoiceComment voiceComment = (VoiceComment) comment;
49+
assertEquals(Long.valueOf(COMMENT_ID), voiceComment.getId());
50+
assertEquals(COMMENT_BODY, voiceComment.getBody());
51+
assertEquals(COMMENT_VOICE_URL, voiceComment.getData().getRecordingUrl());
52+
}
53+
54+
@Test
55+
public void explicitTypeTpeVoiceCommentType() throws JsonProcessingException {
56+
String json = createCommentJson("TpeVoiceComment");
57+
Comment comment = parseJson(json);
58+
assertEquals(VoiceComment.class, comment.getClass());
59+
60+
VoiceComment voiceComment = (VoiceComment) comment;
61+
assertEquals(Long.valueOf(COMMENT_ID), voiceComment.getId());
62+
assertEquals(COMMENT_BODY, voiceComment.getBody());
63+
assertEquals(COMMENT_VOICE_URL, voiceComment.getData().getRecordingUrl());
64+
}
65+
66+
@Test
67+
public void invalidType() throws JsonProcessingException {
68+
String json = createCommentJson("InvalidCommentType");
69+
assertThrows(InvalidFormatException.class, () -> parseJson(json));
70+
}
71+
72+
private static String createCommentJson(@Nullable String type) throws JsonProcessingException {
73+
// https://developer.zendesk.com/documentation/ticketing/managing-tickets/adding-voice-comments-to-tickets/
74+
ObjectNode voiceData = MAPPER.createObjectNode()
75+
.put("from", "+16617480240")
76+
.put("to", "+16617480123")
77+
.put("recording_url", COMMENT_VOICE_URL)
78+
.put("started_at", "2019-04-16T09:14:57Z")
79+
.put("call_duration", 42)
80+
.put("answered_by_id", 28765)
81+
.put("transcription_text", "The transcription of the call")
82+
.put("location", "Topeka, Kansas");
83+
84+
ObjectNode res = MAPPER.createObjectNode()
85+
.put("id", COMMENT_ID)
86+
.put("body", "Foo")
87+
.set("data", voiceData);
88+
89+
if (type != null) {
90+
res.put("type", type);
91+
}
92+
93+
return MAPPER.writeValueAsString(res);
94+
}
95+
96+
private static Comment parseJson(String json) throws JsonProcessingException {
97+
return MAPPER.readValue(json, Comment.class);
98+
}
99+
}

0 commit comments

Comments
 (0)