Skip to content

Commit 1543b21

Browse files
committed
Add a dedicated VerifyType enum.
Priorly we used MsgType, but that contains values not appropriate for the Verify endpoint. It was also missing text to speech.
1 parent fbae136 commit 1543b21

File tree

4 files changed

+92
-4
lines changed

4 files changed

+92
-4
lines changed

api/src/main/java/com/messagebird/objects/VerifyRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class VerifyRequest implements Serializable {
1010
private String recipient;
1111
private String originator;
1212
private String reference;
13-
private MsgType type;
13+
private VerifyType type;
1414
private DataCodingType datacoding = DataCodingType.plain;
1515
private String template;
1616
private Integer timeout;
@@ -46,11 +46,11 @@ public void setReference(String reference) {
4646
this.reference = reference;
4747
}
4848

49-
public MsgType getType() {
49+
public VerifyType getType() {
5050
return type;
5151
}
5252

53-
public void setType(MsgType type) {
53+
public void setType(VerifyType type) {
5454
this.type = type;
5555
}
5656

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.messagebird.objects;
2+
3+
import com.fasterxml.jackson.annotation.JsonValue;
4+
5+
/**
6+
* Determines which type the message will be.
7+
*/
8+
public enum VerifyType {
9+
10+
FLASH("flash"),
11+
SMS("sms"),
12+
TTS("tts");
13+
14+
final String value;
15+
16+
VerifyType(String type) {
17+
this.value = type;
18+
}
19+
20+
@JsonValue
21+
public String getValue() {
22+
return value;
23+
}
24+
25+
@Override
26+
public String toString() {
27+
return "VerifyType{" +
28+
"value='" + value + '\'' +
29+
'}';
30+
}
31+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void testSendVerifyToken1() throws UnauthorizedException, GeneralExceptio
319319
verifyRequest.setOriginator("Code");
320320
verifyRequest.setReference(reference);
321321
verifyRequest.setLanguage(Language.NL_NL);
322-
verifyRequest.setType(MsgType.sms);
322+
verifyRequest.setType(VerifyType.SMS);
323323
verifyRequest.setTimeout(30);
324324
verifyRequest.setTokenLength(6);
325325
verifyRequest.setVoice(Gender.FEMALE);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.messagebird;
2+
3+
import com.messagebird.exceptions.GeneralException;
4+
import com.messagebird.exceptions.UnauthorizedException;
5+
import com.messagebird.objects.Verify;
6+
import com.messagebird.objects.VerifyRequest;
7+
import com.messagebird.objects.VerifyType;
8+
9+
import static org.junit.Assert.*;
10+
11+
import org.junit.Test;
12+
13+
public class VerifyTest {
14+
15+
private static final String VERIFY_SMS_RESPONSE = "{\"id\": \"verify-id-sms\",\"href\": \"https://rest.messagebird.com/verify/verify-id-sms\",\"recipient\": 31612345678,\"reference\": null,\"messages\": {\"href\": \"https://rest.messagebird.com/messages/5958c0d5e2df41de8154e5e88bfeb5bc\"},\"status\": \"sent\",\"createdDatetime\": \"2018-09-25T14:38:12+00:00\",\"validUntilDatetime\": \"2018-09-25T14:38:42+00:00\"}";
16+
private static final String VERIFY_TTS_RESPONSE = "{\"id\": \"verify-id-tts\",\"href\": \"https://rest.messagebird.com/verify/verify-id-tts\",\"recipient\": 31612345678,\"reference\": null,\"messages\": {\"href\": \"https://rest.messagebird.com/voicemessages/c043ab473f8e4f2590ab9a16d25f2899\"},\"status\": \"sent\",\"createdDatetime\": \"2018-09-25T14:35:10+00:00\",\"validUntilDatetime\": \"2018-09-25T14:35:40+00:00\"}";
17+
18+
@Test
19+
public void testSendVerifyTokenSms() throws GeneralException, UnauthorizedException {
20+
VerifyRequest verifyRequest = new VerifyRequest("31612345678");
21+
verifyRequest.setType(VerifyType.SMS);
22+
23+
MessageBirdService messageBirdService = SpyService
24+
.expects("POST", "verify", verifyRequest)
25+
.withRestAPIBaseURL()
26+
.andReturns(new APIResponse(VERIFY_SMS_RESPONSE, 200));
27+
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);
28+
29+
Verify verify = messageBirdClient.sendVerifyToken(verifyRequest);
30+
31+
assertEquals("verify-id-sms", verify.getId());
32+
}
33+
34+
@Test
35+
public void testSendVerifyTokenTts() throws GeneralException, UnauthorizedException {
36+
VerifyRequest verifyRequest = new VerifyRequest("31612345678");
37+
verifyRequest.setType(VerifyType.TTS);
38+
39+
MessageBirdService messageBirdService = SpyService
40+
.expects("POST", "verify", verifyRequest)
41+
.withRestAPIBaseURL()
42+
.andReturns(new APIResponse(VERIFY_TTS_RESPONSE, 200));
43+
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);
44+
45+
Verify verify = messageBirdClient.sendVerifyToken(verifyRequest);
46+
47+
assertEquals("verify-id-tts", verify.getId());
48+
}
49+
50+
@Test
51+
public void testVerifyTypeValue() {
52+
// Important for generating proper JSON payloads...
53+
assertEquals("flash", VerifyType.FLASH.getValue());
54+
assertEquals("sms", VerifyType.SMS.getValue());
55+
assertEquals("tts", VerifyType.TTS.getValue());
56+
}
57+
}

0 commit comments

Comments
 (0)