Skip to content

Add a dedicated VerifyType enum. #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/src/main/java/com/messagebird/objects/VerifyRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class VerifyRequest implements Serializable {
private String recipient;
private String originator;
private String reference;
private MsgType type;
private VerifyType type;
private DataCodingType datacoding = DataCodingType.plain;
private String template;
private Integer timeout;
Expand Down Expand Up @@ -46,11 +46,11 @@ public void setReference(String reference) {
this.reference = reference;
}

public MsgType getType() {
public VerifyType getType() {
return type;
}

public void setType(MsgType type) {
public void setType(VerifyType type) {
this.type = type;
}

Expand Down
31 changes: 31 additions & 0 deletions api/src/main/java/com/messagebird/objects/VerifyType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.messagebird.objects;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* Determines which type the message will be.
*/
public enum VerifyType {

FLASH("flash"),
SMS("sms"),
TTS("tts");

final String value;

VerifyType(String type) {
this.value = type;
}

@JsonValue
public String getValue() {
return value;
}

@Override
public String toString() {
return "VerifyType{" +
"value='" + value + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void testSendVerifyToken1() throws UnauthorizedException, GeneralExceptio
verifyRequest.setOriginator("Code");
verifyRequest.setReference(reference);
verifyRequest.setLanguage(Language.NL_NL);
verifyRequest.setType(MsgType.sms);
verifyRequest.setType(VerifyType.SMS);
verifyRequest.setTimeout(30);
verifyRequest.setTokenLength(6);
verifyRequest.setVoice(Gender.FEMALE);
Expand Down
57 changes: 57 additions & 0 deletions api/src/test/java/com/messagebird/VerifyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.messagebird;

import com.messagebird.exceptions.GeneralException;
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.Verify;
import com.messagebird.objects.VerifyRequest;
import com.messagebird.objects.VerifyType;

import static org.junit.Assert.*;

import org.junit.Test;

public class VerifyTest {

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\"}";
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\"}";

@Test
public void testSendVerifyTokenSms() throws GeneralException, UnauthorizedException {
VerifyRequest verifyRequest = new VerifyRequest("31612345678");
verifyRequest.setType(VerifyType.SMS);

MessageBirdService messageBirdService = SpyService
.expects("POST", "verify", verifyRequest)
.withRestAPIBaseURL()
.andReturns(new APIResponse(VERIFY_SMS_RESPONSE, 200));
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);

Verify verify = messageBirdClient.sendVerifyToken(verifyRequest);

assertEquals("verify-id-sms", verify.getId());
}

@Test
public void testSendVerifyTokenTts() throws GeneralException, UnauthorizedException {
VerifyRequest verifyRequest = new VerifyRequest("31612345678");
verifyRequest.setType(VerifyType.TTS);

MessageBirdService messageBirdService = SpyService
.expects("POST", "verify", verifyRequest)
.withRestAPIBaseURL()
.andReturns(new APIResponse(VERIFY_TTS_RESPONSE, 200));
MessageBirdClient messageBirdClient = new MessageBirdClient(messageBirdService);

Verify verify = messageBirdClient.sendVerifyToken(verifyRequest);

assertEquals("verify-id-tts", verify.getId());
}

@Test
public void testVerifyTypeValue() {
// Important for generating proper JSON payloads...
assertEquals("flash", VerifyType.FLASH.getValue());
assertEquals("sms", VerifyType.SMS.getValue());
assertEquals("tts", VerifyType.TTS.getValue());
}
}