Skip to content

Commit

Permalink
feat: NextWorkflow for VerifyV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Apr 11, 2024
1 parent 11bb4ef commit 46cf5f0
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Vonage.Test/VerifyV2/NextWorkflow/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Vonage.Test.Common.Extensions;
using Vonage.VerifyV2.NextWorkflow;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Test.VerifyV2.NextWorkflow;

[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
[Fact]
public async Task NextWorkflow()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v2/verify/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb/next_workflow")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingPost())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK));
await this.Helper.VonageClient.VerifyV2Client.NextWorkflowAsync(
NextWorkflowRequest.Parse(Guid.Parse("68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb")))
.Should()
.BeSuccessAsync();
}
}
30 changes: 30 additions & 0 deletions Vonage.Test/VerifyV2/NextWorkflow/RequestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using Vonage.Test.Common.Extensions;
using Vonage.VerifyV2.NextWorkflow;
using Xunit;

namespace Vonage.Test.VerifyV2.NextWorkflow;

[Trait("Category", "Request")]
public class RequestTest
{
[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint() =>
NextWorkflowRequest.Parse(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287"))
.Map(request => request.GetEndpointPath())
.Should()
.BeSuccess("/v2/verify/f3a065af-ac5a-47a4-8dfe-819561a7a287/next_workflow");

[Fact]
public void Parse_ShouldReturnFailure_GivenRequestIsEmpty() =>
NextWorkflowRequest.Parse(Guid.Empty)
.Should()
.BeParsingFailure("RequestId cannot be empty.");

[Fact]
public void Parse_ShouldReturnSuccess() =>
NextWorkflowRequest.Parse(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287"))
.Map(request => request.RequestId)
.Should()
.BeSuccess(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287"));
}
8 changes: 8 additions & 0 deletions Vonage/VerifyV2/IVerifyV2Client.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Vonage.Common.Monads;
using Vonage.VerifyV2.Cancel;
using Vonage.VerifyV2.NextWorkflow;
using Vonage.VerifyV2.StartVerification;
using Vonage.VerifyV2.VerifyCode;

Expand All @@ -18,6 +19,13 @@ public interface IVerifyV2Client
/// <returns>Success or Failure.</returns>
Task<Result<Unit>> CancelAsync(Result<CancelRequest> request);

/// <summary>
/// Move the request onto the next workflow, if available.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Success or Failure.</returns>
Task<Result<Unit>> NextWorkflowAsync(Result<NextWorkflowRequest> request);

/// <summary>
/// Requests a verification to be sent to a user.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions Vonage/VerifyV2/NextWorkflow/NextWorkflowRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Net.Http;
using Vonage.Common.Client;
using Vonage.Common.Monads;
using Vonage.Common.Validation;

namespace Vonage.VerifyV2.NextWorkflow;

/// <inheritdoc />
public readonly struct NextWorkflowRequest : IVonageRequest
{
private NextWorkflowRequest(Guid requestId) => this.RequestId = requestId;

/// <summary>
/// ID of the verify request.
/// </summary>
public Guid RequestId { get; internal init; }

/// <inheritdoc />
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder
.Initialize(HttpMethod.Post, this.GetEndpointPath())
.Build();

/// <inheritdoc />
public string GetEndpointPath() => $"/v2/verify/{this.RequestId}/next_workflow";

/// <summary>
/// Parses the input into a NextWorkflowRequest.
/// </summary>
/// <param name="requestId">The verify request identifier.</param>
/// <returns>A success state with the request if the parsing succeeded. A failure state with an error if it failed.</returns>
public static Result<NextWorkflowRequest> Parse(Guid requestId) =>
Result<NextWorkflowRequest>
.FromSuccess(new NextWorkflowRequest(requestId))
.Map(InputEvaluation<NextWorkflowRequest>.Evaluate)
.Bind(evaluation => evaluation.WithRules(VerifyRequestId));

private static Result<NextWorkflowRequest> VerifyRequestId(NextWorkflowRequest request) =>
InputValidation.VerifyNotEmpty(request, request.RequestId, nameof(RequestId));
}
5 changes: 5 additions & 0 deletions Vonage/VerifyV2/VerifyV2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Vonage.Common.Monads;
using Vonage.Serialization;
using Vonage.VerifyV2.Cancel;
using Vonage.VerifyV2.NextWorkflow;
using Vonage.VerifyV2.StartVerification;
using Vonage.VerifyV2.VerifyCode;

Expand All @@ -23,6 +24,10 @@ internal VerifyV2Client(VonageHttpClientConfiguration configuration) =>
public Task<Result<Unit>> CancelAsync(Result<CancelRequest> request) =>
this.vonageClient.SendAsync(request);

/// <inheritdoc />
public Task<Result<Unit>> NextWorkflowAsync(Result<NextWorkflowRequest> request) =>
this.vonageClient.SendAsync(request);

/// <inheritdoc />
public Task<Result<StartVerificationResponse>> StartVerificationAsync(Result<StartVerificationRequest> request) =>
this.vonageClient.SendWithResponseAsync<StartVerificationRequest, StartVerificationResponse>(request);
Expand Down

0 comments on commit 46cf5f0

Please sign in to comment.