From 11bb4ef8dfd18c8a8c27cdf9af7349ca07561bdf Mon Sep 17 00:00:00 2001 From: tr00d Date: Tue, 9 Apr 2024 11:02:08 +0200 Subject: [PATCH] feat: Brand is now limiter to 16 characters in VerifyV2 --- .../StartVerification/RequestBuilderTest.cs | 15 ++++++- .../VerifyV2/StartVerification/RequestTest.cs | 5 +-- .../StartVerificationRequestBuilder.cs | 39 +++++++++++-------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs b/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs index 644fb6f5e..299d0957d 100644 --- a/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs +++ b/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs @@ -2,6 +2,7 @@ using Vonage.Common.Failures; using Vonage.Common.Monads; using Vonage.Test.Common.Extensions; +using Vonage.Test.Common.TestHelpers; using Vonage.VerifyV2.StartVerification; using Vonage.VerifyV2.StartVerification.Email; using Vonage.VerifyV2.StartVerification.SilentAuth; @@ -38,6 +39,15 @@ public void Create_ShouldReturnFailure_GivenBrandIsNullOrWhitespace(string value .Should() .BeParsingFailure("Brand cannot be null or whitespace."); + [Fact] + public void Create_ShouldReturnFailure_GivenBrandExceeds16Characters() => + StartVerificationRequest.Build() + .WithBrand(StringHelper.GenerateString(17)) + .WithWorkflow(EmailWorkflow.Parse(ValidEmail)) + .Create() + .Should() + .BeParsingFailure("Brand length cannot be higher than 16."); + [Fact] public void Create_ShouldReturnFailure_GivenChannelTimeoutIsHigherThanMaximum() => BuildBaseRequest() @@ -88,12 +98,13 @@ public void Create_ShouldReturnFailure_GivenOneFallbackWorkflowIsFailure() => [Fact] public void Create_ShouldSetBrand() => - BuildBaseRequest() + StartVerificationRequest.Build() + .WithBrand("Brand Custom 123") .WithWorkflow(SilentAuthWorkflow.Parse("123456789")) .Create() .Map(request => request.Brand) .Should() - .BeSuccess("some brand"); + .BeSuccess("Brand Custom 123"); [Theory] [InlineData(60)] diff --git a/Vonage.Test/VerifyV2/StartVerification/RequestTest.cs b/Vonage.Test/VerifyV2/StartVerification/RequestTest.cs index 9b6f41979..57498c8ed 100644 --- a/Vonage.Test/VerifyV2/StartVerification/RequestTest.cs +++ b/Vonage.Test/VerifyV2/StartVerification/RequestTest.cs @@ -1,4 +1,3 @@ -using AutoFixture; using Vonage.Test.Common.Extensions; using Vonage.VerifyV2.StartVerification; using Vonage.VerifyV2.StartVerification.Sms; @@ -9,12 +8,10 @@ namespace Vonage.Test.VerifyV2.StartVerification; [Trait("Category", "Request")] public class RequestTest { - private readonly Fixture fixture = new Fixture(); - [Fact] public void GetEndpointPath_ShouldReturnApiEndpoint() => StartVerificationRequest.Build() - .WithBrand(this.fixture.Create()) + .WithBrand("MyBrand") .WithWorkflow(SmsWorkflow.Parse("123456789")) .Create() .Map(request => request.GetEndpointPath()) diff --git a/Vonage/VerifyV2/StartVerification/StartVerificationRequestBuilder.cs b/Vonage/VerifyV2/StartVerification/StartVerificationRequestBuilder.cs index b826f742b..132257a08 100644 --- a/Vonage/VerifyV2/StartVerification/StartVerificationRequestBuilder.cs +++ b/Vonage/VerifyV2/StartVerification/StartVerificationRequestBuilder.cs @@ -11,15 +11,26 @@ internal class StartVerificationRequestBuilder : IBuilderForBrand, IBuilderForWorkflow { - private bool fraudCheck = true; + private const int MaxBrandLength = 16; + private readonly List workflows = new List(); + private string brand; private int channelTimeout = 300; - private int codeLength = 4; - private readonly List workflows = new(); - private Locale locale = Locale.EnUs; - private Maybe failure = Maybe.None; private Maybe clientReference = Maybe.None; private Maybe code; - private string brand; + private int codeLength = 4; + private Maybe failure = Maybe.None; + private bool fraudCheck = true; + private Locale locale = Locale.EnUs; + + /// + public IBuilderForWorkflow WithBrand(string value) + { + this.brand = value; + return this; + } + + /// + public IOptionalBuilder WithWorkflow(Result value) where T : IVerificationWorkflow => this.SetWorkflow(value); /// public Result Create() => @@ -40,6 +51,7 @@ public Result Create() => .Map(InputEvaluation.Evaluate) .Bind(evaluation => evaluation.WithRules( VerifyBrandNotEmpty, + VerifyBrandLength, VerifyChannelTimeoutHigherThanMinimum, VerifyChannelTimeoutLowerThanMaximum, VerifyCodeLengthHigherThanMinimum, @@ -52,13 +64,6 @@ public IOptionalBuilder SkipFraudCheck() return this; } - /// - public IBuilderForWorkflow WithBrand(string value) - { - this.brand = value; - return this; - } - /// public IOptionalBuilder WithChannelTimeout(int value) { @@ -98,9 +103,6 @@ public IOptionalBuilder WithLocale(string value) return this; } - /// - public IOptionalBuilder WithWorkflow(Result value) where T : IVerificationWorkflow => this.SetWorkflow(value); - private Unit AddWorkflow(T workflow) where T : IVerificationWorkflow { this.workflows.Add(workflow); @@ -128,6 +130,11 @@ private static Result VerifyBrandNotEmpty( InputValidation .VerifyNotEmpty(request, request.Brand, nameof(request.Brand)); + private static Result VerifyBrandLength( + StartVerificationRequest request) => + InputValidation + .VerifyLengthLowerOrEqualThan(request, request.Brand, MaxBrandLength, nameof(request.Brand)); + private static Result VerifyChannelTimeoutHigherThanMinimum( StartVerificationRequest request) => InputValidation