Skip to content

Commit

Permalink
feat: implement BuildVerificationRequest on StartVerificationResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Nov 20, 2023
1 parent c0f10a8 commit 27dfe16
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using FluentAssertions;
using Vonage.Common.Monads;
using Vonage.Common.Test.Extensions;
using Vonage.VerifyV2.StartVerification;
using Xunit;

namespace Vonage.Test.Unit.VerifyV2.StartVerification
{
public class StartVerificationResponseTest
{
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void BuildVerificationRequest_ShouldReturnFailure_GivenCodeIsNullOrWhitespace(string value) =>
new StartVerificationResponse(Guid.NewGuid(), Maybe<Uri>.None)
.BuildVerificationRequest(value)
.Should()
.BeParsingFailure("Code cannot be null or whitespace.");

[Fact]
public void BuildVerificationRequest_ShouldReturnSuccess() =>
new StartVerificationResponse(new Guid("06547d61-7ac0-43bb-94bd-503b24b2a3a5"), Maybe<Uri>.None)
.BuildVerificationRequest("Some code.")
.Should()
.BeSuccess(request =>
{
request.RequestId.Should().Be(new Guid("06547d61-7ac0-43bb-94bd-503b24b2a3a5"));
request.Code.Should().Be("Some code.");
});
}
}
4 changes: 1 addition & 3 deletions Vonage.Test.Unit/VerifyV2/VerifyCode/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Vonage.Test.Unit.VerifyV2.VerifyCode
{
public class RequestBuilderTest
{
private readonly Fixture fixture;

public RequestBuilderTest() => this.fixture = new Fixture();
private readonly Fixture fixture = new Fixture();

[Theory]
[InlineData("")]
Expand Down
12 changes: 11 additions & 1 deletion Vonage/VerifyV2/StartVerification/StartVerificationResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json.Serialization;
using Vonage.Common.Monads;
using Vonage.Common.Serialization;
using Vonage.VerifyV2.VerifyCode;

namespace Vonage.VerifyV2.StartVerification;

Expand All @@ -15,4 +16,13 @@ public record StartVerificationResponse(
[property: JsonPropertyOrder(1)]
[property: JsonConverter(typeof(MaybeJsonConverter<Uri>))]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
Maybe<Uri> CheckUrl);
Maybe<Uri> CheckUrl)
{
/// <summary>
/// Builds a VerifyCodeRequest based on the current request.
/// </summary>
/// <param name="verificationCode">The verification code.</param>
/// <returns>A request to verify the code for the current process.</returns>
public Result<VerifyCodeRequest> BuildVerificationRequest(string verificationCode) => VerifyCodeRequest.Build()
.WithRequestId(this.RequestId).WithCode(verificationCode).Create();
}

0 comments on commit 27dfe16

Please sign in to comment.