From 27dfe161e73fb0912934ef42ec7dac385d9a18e7 Mon Sep 17 00:00:00 2001 From: Guillaume Faas Date: Mon, 20 Nov 2023 13:57:06 +0100 Subject: [PATCH] feat: implement BuildVerificationRequest on StartVerificationResponse --- .../StartVerificationResponseTest.cs | 33 +++++++++++++++++++ .../VerifyV2/VerifyCode/RequestBuilderTest.cs | 4 +-- .../StartVerificationResponse.cs | 12 ++++++- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 Vonage.Test.Unit/VerifyV2/StartVerification/StartVerificationResponseTest.cs diff --git a/Vonage.Test.Unit/VerifyV2/StartVerification/StartVerificationResponseTest.cs b/Vonage.Test.Unit/VerifyV2/StartVerification/StartVerificationResponseTest.cs new file mode 100644 index 000000000..d3536d918 --- /dev/null +++ b/Vonage.Test.Unit/VerifyV2/StartVerification/StartVerificationResponseTest.cs @@ -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.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.None) + .BuildVerificationRequest("Some code.") + .Should() + .BeSuccess(request => + { + request.RequestId.Should().Be(new Guid("06547d61-7ac0-43bb-94bd-503b24b2a3a5")); + request.Code.Should().Be("Some code."); + }); + } +} \ No newline at end of file diff --git a/Vonage.Test.Unit/VerifyV2/VerifyCode/RequestBuilderTest.cs b/Vonage.Test.Unit/VerifyV2/VerifyCode/RequestBuilderTest.cs index 20eb1d83a..ccb4caee5 100644 --- a/Vonage.Test.Unit/VerifyV2/VerifyCode/RequestBuilderTest.cs +++ b/Vonage.Test.Unit/VerifyV2/VerifyCode/RequestBuilderTest.cs @@ -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("")] diff --git a/Vonage/VerifyV2/StartVerification/StartVerificationResponse.cs b/Vonage/VerifyV2/StartVerification/StartVerificationResponse.cs index 2293e2dd8..da82f3e11 100644 --- a/Vonage/VerifyV2/StartVerification/StartVerificationResponse.cs +++ b/Vonage/VerifyV2/StartVerification/StartVerificationResponse.cs @@ -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; @@ -15,4 +16,13 @@ public record StartVerificationResponse( [property: JsonPropertyOrder(1)] [property: JsonConverter(typeof(MaybeJsonConverter))] [property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - Maybe CheckUrl); \ No newline at end of file + Maybe CheckUrl) +{ + /// + /// Builds a VerifyCodeRequest based on the current request. + /// + /// The verification code. + /// A request to verify the code for the current process. + public Result BuildVerificationRequest(string verificationCode) => VerifyCodeRequest.Build() + .WithRequestId(this.RequestId).WithCode(verificationCode).Create(); +} \ No newline at end of file