Skip to content

Commit

Permalink
fix: Verify v1 length overload method (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani authored Dec 13, 2023
1 parent 07afa55 commit 677cb02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/vonage/client/account/AccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public ListSecretsResponse listSecrets(String apiKey) throws AccountResponseExce
* @return SecretResponse object which contains the results from the API.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*
* @since 7.9.0
*/
public SecretResponse getSecret(String secretId) throws AccountResponseException {
return getSecret(apiKeyGetter.get(), secretId);
Expand Down Expand Up @@ -250,6 +252,8 @@ public SecretResponse getSecret(String apiKey, String secretId) throws AccountRe
* @return SecretResponse object which contains the created secret from the API.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*
* @since 7.9.0
*/
public SecretResponse createSecret(String secret) throws AccountResponseException {
return createSecret(apiKeyGetter.get(), secret);
Expand Down Expand Up @@ -277,6 +281,8 @@ public SecretResponse createSecret(String apiKey, String secret) throws AccountR
* @param secretId The id of the secret to revoke.
*
* @throws AccountResponseException If there was an error making the request or retrieving the response.
*
* @since 7.9.0
*/
public void revokeSecret(String secretId) throws AccountResponseException {
revokeSecret(apiKeyGetter.get(), secretId);
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/vonage/client/verify/VerifyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ public VerifyResponse verify(final String number,
final String from,
final int length,
final Locale locale) throws VonageClientException, VonageResponseParseException {
return verify(new VerifyRequest.Builder(number, brand)
.senderId(from)
.locale(locale)
.build()
);
return verify(VerifyRequest.builder(number, brand).length(length).senderId(from).locale(locale).build());
}

/**
Expand Down Expand Up @@ -209,7 +205,6 @@ public CheckResponse check(final String requestId, final String code) throws Von
return check(new CheckRequest(requestId, code));
}


/**
* Search for a previous verification request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,6 @@ public VerifyClientVerifyEndpointTest() {
client = new VerifyClient(wrapper);
}

@Test
public void testVerifyWithNumberBrandFromLengthLocaleLineType() throws Exception {
stubResponse(200,
"{\n" + " \"request_id\": \"not-really-a-request-id\",\n" + " \"status\": 0,\n"
+ " \"error_text\": \"error\"\n" + "}"
);

VerifyResponse response = client.verify("447700900999",
"TestBrand",
"15555215554",
6,
Locale.US
);

assertEquals(VerifyStatus.OK, response.getStatus());
assertEquals("error", response.getErrorText());
assertEquals("not-really-a-request-id", response.getRequestId());
}

@Test
public void testVerifyWithNumberBrandFromLengthLocale() throws Exception {
stubResponse(200,
Expand Down Expand Up @@ -131,7 +112,8 @@ public void testVerifyWithNonNumericStatus() throws Exception {
.senderId("15555215554")
.length(6)
.locale(Locale.US)
.build());
.build()
);

assertEquals(VerifyStatus.INTERNAL_ERROR, response.getStatus());
assertEquals("error", response.getErrorText());
Expand Down Expand Up @@ -195,7 +177,7 @@ protected VerifyRequest sampleRequest() {
}

@Override
protected Map<String, ?> sampleQueryParams() {
protected Map<String, String> sampleQueryParams() {
Map<String, String> params = new LinkedHashMap<>();
params.put("number", "4477990090090");
params.put("brand", "Brand.com");
Expand All @@ -207,7 +189,17 @@ protected VerifyRequest sampleRequest() {
params.put("pin_expiry", "60");
params.put("next_event_wait", "90");
params.put("workflow_id", "3");
return params;
}

@Override
public void runTests() throws Exception {
super.runTests();
assertQueryParamsMatchRequest();
}

private void assertQueryParamsMatchRequest() {
Map<String, String> params = sampleQueryParams();
VerifyRequest request = sampleRequest();
assertNotNull(request.toString());
assertEquals(request.getNumber(), params.get("number"));
Expand All @@ -220,8 +212,6 @@ protected VerifyRequest sampleRequest() {
assertEquals(request.getPinExpiry().toString(), params.get("pin_expiry"));
assertEquals(request.getNextEventWait().toString(), params.get("next_event_wait"));
assertEquals(String.valueOf(request.getWorkflow().getId()), params.get("workflow_id"));

return params;
}
}
.runTests();
Expand Down

0 comments on commit 677cb02

Please sign in to comment.