Skip to content

Commit

Permalink
fix: checkVerificationCode returns response body
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jul 12, 2024
1 parent 82117c5 commit ff206e5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
# [8.9.2] - 2024-07-12
- Refactoring to accommodate using v2.0.0 of Vonage JWT library
- Made `timestamp` optional in Conversion API
- Added response object to `Verify2Client.checkVerificationCode`
- Fixed `SpeechSettings.Language.NEPALI` (de)serialisation
- `fromRandomNumber` true if `from` is not specified in `Call.Builder`
- Fixed `com.vonage.client.voice.EventWebhook` deserialisation issue
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/vonage/client/verify2/Verify2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class Verify2Client {
final boolean hasJwtAuthMethod;
final RestEndpoint<VerificationRequest, VerificationResponse> verifyUser;
final RestEndpoint<VerifyCodeRequestWrapper, Void> verifyRequest;
final RestEndpoint<VerifyCodeRequestWrapper, VerifyCodeResponse> verifyRequest;
final RestEndpoint<UUID, Void> cancel, nextWorkflow;

/**
Expand Down Expand Up @@ -115,10 +115,12 @@ public VerificationResponse sendVerification(VerificationRequest request) {
* @param requestId ID of the verify request, obtained from {@link VerificationResponse#getRequestId()}.
* @param code The code supplied by the user.
*
* @return Details of the verification request (if the code matched).
*
* @throws VerifyResponseException If the code was invalid, or any other error.
*/
public void checkVerificationCode(UUID requestId, String code) {
verifyRequest.execute(new VerifyCodeRequestWrapper(
public VerifyCodeResponse checkVerificationCode(UUID requestId, String code) {
return verifyRequest.execute(new VerifyCodeRequestWrapper(
validateRequestId(requestId).toString(),
Objects.requireNonNull(code, "Code is required.")
));
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/vonage/client/verify2/VerifyCodeResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2024 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.verify2;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.JsonableBaseObject;
import java.util.UUID;

/**
* Represents the response from {@link Verify2Client#checkVerificationCode(UUID, String)}.
*
* @since 8.9.2
*/
public final class VerifyCodeResponse extends JsonableBaseObject {
private UUID requestId;
private VerificationStatus status;

private VerifyCodeResponse() {}

/**
* ID of the verify request.
*
* @return The verify request ID.
*/
@JsonProperty("request_id")
public UUID getRequestId() {
return requestId;
}

/**
* Status of the verification workflow.
*
* @return The status as an enum.
*/
@JsonProperty("status")
public VerificationStatus getStatus() {
return status;
}
}
18 changes: 14 additions & 4 deletions src/test/java/com/vonage/client/verify2/Verify2ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.vonage.client.AbstractClientTest;
import com.vonage.client.HttpWrapper;
import com.vonage.client.RestEndpoint;
import com.vonage.client.TestUtils;
import com.vonage.client.common.HttpMethod;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
Expand All @@ -28,7 +29,7 @@
import java.util.UUID;

public class Verify2ClientTest extends AbstractClientTest<Verify2Client> {
static final UUID REQUEST_ID = UUID.randomUUID();
static final UUID REQUEST_ID = UUID.fromString("90596ac8-e1f1-46a9-a80f-ebd55e2296ae");
static final String CODE = "1234";
static final String VERIFICATION_RESPONSE = "{\"request_id\": \""+REQUEST_ID+"\"}";

Expand Down Expand Up @@ -192,10 +193,19 @@ void testParseResponseFailureAllParams() throws Exception {
}

@Test
public void testVerifyCodeSuccess() throws Exception {
public void testVerifyCodeSuccessNoResponse() throws Exception {
stubResponseAndRun(204, () -> client.checkVerificationCode(REQUEST_ID, CODE));
}

@Test
public void testVerifyCodeSuccess() throws Exception {
stubResponse(200, VERIFICATION_RESPONSE.replace("}", ",\"status\":\"completed\"}"));
VerifyCodeResponse parsed = client.checkVerificationCode(REQUEST_ID, CODE);
TestUtils.testJsonableBaseObject(parsed);
assertEquals(REQUEST_ID, parsed.getRequestId());
assertEquals(VerificationStatus.COMPLETED, parsed.getStatus());
}

@Test
public void testVerifyCodeFailure() throws Exception {
assert429ResponseException(() -> client.checkVerificationCode(REQUEST_ID, CODE));
Expand All @@ -212,10 +222,10 @@ public void testVerifyCodeFailure() throws Exception {

@Test
public void testVerifyCodeEndpoint() throws Exception {
new Verify2EndpointTestSpec<VerifyCodeRequestWrapper, Void>() {
new Verify2EndpointTestSpec<VerifyCodeRequestWrapper, VerifyCodeResponse>() {

@Override
protected RestEndpoint<VerifyCodeRequestWrapper, Void> endpoint() {
protected RestEndpoint<VerifyCodeRequestWrapper, VerifyCodeResponse> endpoint() {
return client.verifyRequest;
}

Expand Down

0 comments on commit ff206e5

Please sign in to comment.