Skip to content

Commit

Permalink
100% Verify v2 coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jan 16, 2025
1 parent c60599f commit 675d384
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static final class LocaleSerializer extends StdConverter<Locale, String>

@Override
public String convert(Locale value) {
return value == null ? null : value.toString().toLowerCase().replace('_', '-');
return value.toString().toLowerCase().replace('_', '-');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void testParseRequestUpdateMultipleWorkflows() {
" }\n" +
" ],\n" +
" \"price\": \"0.300000125\",\n" +
" \"client_ref\": \"my-personal-ref\"\n" +
" \"client_ref\": \"my-personal-ref\",\n" +
" \"action\": {}\n" +
"}"
);
TestUtils.testJsonableBaseObject(webhook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,13 @@ public void testSilentAuthMustBeFirstWorkflow() {
}

@Test
public void testInvalidLocale() throws Exception {
public void testInvalidLocale() {
VerificationRequest.Builder builder = getBuilderRequiredParamsSingleWorkflow(Channel.SMS);
assertThrows(IllegalArgumentException.class, () -> builder.locale("--++").build());
assertThrows(IllegalArgumentException.class, () -> builder.locale("en_GB").build());
assertThrows(IllegalArgumentException.class, () -> builder.locale(" ").build());
assertThrows(IllegalArgumentException.class, () -> builder.locale((Locale) null).build());
assertThrows(NullPointerException.class, () -> builder.locale((String) null).build());
assertNotNull(builder.locale("ab-cd").build().getLocale());
}

Expand Down
22 changes: 19 additions & 3 deletions src/test/java/com/vonage/client/verify2/Verify2ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import com.vonage.client.*;
import static com.vonage.client.TestUtils.testJsonableBaseObject;
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
import com.vonage.client.auth.NoAuthMethod;
import com.vonage.client.common.HttpMethod;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
Expand Down Expand Up @@ -152,6 +154,9 @@ void stubSuccessfulVerifyUserResponseAndRun(VerificationRequest request) throws
@Test
public void testVerifyUserSuccess() throws Exception {
stubSuccessfulVerifyUserResponseAndRun(newVerificationRequestWithAllParamsAndWorkflows());
stubSuccessfulVerifyUserResponseAndRun(VerificationRequest.builder()
.brand("Vonage").addWorkflow(new SilentAuthWorkflow("447700900001")).build()
);
}

@Test
Expand Down Expand Up @@ -199,16 +204,16 @@ protected String sampleRequestBodyString() {
@Override
public void runTests() throws Exception {
super.runTests();
testCodelessAndBasicAuth();
testCodelessAndNoJwtAuth();
testParseResponseFailureAllParams();
testParseResponseFailureNoBody();
}

void testCodelessAndBasicAuth() throws Exception {
void testCodelessAndNoJwtAuth() throws Exception {
VerificationRequest request = VerificationRequest.builder()
.brand("Vonage").addWorkflow(new SilentAuthWorkflow("447700900001")).build();

Verify2Client tempClient = new Verify2Client(new HttpWrapper());
var tempClient = new Verify2Client(new HttpWrapper());
assertThrows(IllegalStateException.class, () -> tempClient.sendVerification(request));
String expectedJson = "{\"brand\":\""+request.getBrand() +
"\",\"workflow\":[{\"channel\":\"silent_auth\",\"to\":\"447700900001\"}]}";
Expand Down Expand Up @@ -619,6 +624,9 @@ protected UUID sampleRequest() {
public void testGetTemplateFragmentSuccess() throws Exception {
stubResponse(200, FRAGMENT_RESPONSE);
assertEqualsSampleFragment(client.getTemplateFragment(TEMPLATE_ID, FRAGMENT_ID));

stubResponse(200, "{\"locale\":null}");
assertEqualsEmptyFragment(client.getTemplateFragment(TEMPLATE_ID, FRAGMENT_ID));
}

@Test
Expand Down Expand Up @@ -934,6 +942,10 @@ public void testListTemplatesSuccess() throws Exception {
assertEquals(2, templates.size());
assertEqualsEmptyTemplate(templates.getFirst());
assertEqualsSampleTemplate(templates.getLast());

stubResponse(200, "{}");
templates = client.listTemplates();
assertNull(templates);
}

@Test
Expand Down Expand Up @@ -1050,6 +1062,10 @@ public void testListTemplateFragmentsSuccess() throws Exception {
assertEquals(2, fragments.size());
assertEqualsEmptyFragment(fragments.getFirst());
assertEqualsSampleFragment(fragments.getLast());

stubResponse(200, "{}");
fragments = client.listTemplateFragments(TEMPLATE_ID);
assertNull(fragments);
}

@Test
Expand Down

0 comments on commit 675d384

Please # to comment.