Skip to content

Commit

Permalink
feat: Brand is now limiter to 16 characters in VerifyV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Apr 9, 2024
1 parent f15e7a4 commit 11bb4ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
15 changes: 13 additions & 2 deletions Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,6 +39,15 @@ public class RequestBuilderTest
.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()
Expand Down Expand Up @@ -88,12 +98,13 @@ public class RequestBuilderTest

[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)]
Expand Down
5 changes: 1 addition & 4 deletions Vonage.Test/VerifyV2/StartVerification/RequestTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using AutoFixture;
using Vonage.Test.Common.Extensions;
using Vonage.VerifyV2.StartVerification;
using Vonage.VerifyV2.StartVerification.Sms;
Expand All @@ -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<string>())
.WithBrand("MyBrand")
.WithWorkflow(SmsWorkflow.Parse("123456789"))
.Create()
.Map(request => request.GetEndpointPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ internal class StartVerificationRequestBuilder :
IBuilderForBrand,
IBuilderForWorkflow
{
private bool fraudCheck = true;
private const int MaxBrandLength = 16;
private readonly List<IVerificationWorkflow> workflows = new List<IVerificationWorkflow>();
private string brand;
private int channelTimeout = 300;
private int codeLength = 4;
private readonly List<IVerificationWorkflow> workflows = new();
private Locale locale = Locale.EnUs;
private Maybe<IResultFailure> failure = Maybe<IResultFailure>.None;
private Maybe<string> clientReference = Maybe<string>.None;
private Maybe<string> code;
private string brand;
private int codeLength = 4;
private Maybe<IResultFailure> failure = Maybe<IResultFailure>.None;
private bool fraudCheck = true;
private Locale locale = Locale.EnUs;

/// <inheritdoc />
public IBuilderForWorkflow WithBrand(string value)
{
this.brand = value;
return this;
}

/// <inheritdoc />
public IOptionalBuilder WithWorkflow<T>(Result<T> value) where T : IVerificationWorkflow => this.SetWorkflow(value);

/// <inheritdoc />
public Result<StartVerificationRequest> Create() =>
Expand All @@ -40,6 +51,7 @@ internal class StartVerificationRequestBuilder :
.Map(InputEvaluation<StartVerificationRequest>.Evaluate)
.Bind(evaluation => evaluation.WithRules(
VerifyBrandNotEmpty,
VerifyBrandLength,
VerifyChannelTimeoutHigherThanMinimum,
VerifyChannelTimeoutLowerThanMaximum,
VerifyCodeLengthHigherThanMinimum,
Expand All @@ -52,13 +64,6 @@ public IOptionalBuilder SkipFraudCheck()
return this;
}

/// <inheritdoc />
public IBuilderForWorkflow WithBrand(string value)
{
this.brand = value;
return this;
}

/// <inheritdoc />
public IOptionalBuilder WithChannelTimeout(int value)
{
Expand Down Expand Up @@ -98,9 +103,6 @@ public IOptionalBuilder WithLocale(string value)
return this;
}

/// <inheritdoc />
public IOptionalBuilder WithWorkflow<T>(Result<T> value) where T : IVerificationWorkflow => this.SetWorkflow(value);

private Unit AddWorkflow<T>(T workflow) where T : IVerificationWorkflow
{
this.workflows.Add(workflow);
Expand Down Expand Up @@ -128,6 +130,11 @@ private Unit SetFailure(IResultFailure failureValue)
InputValidation
.VerifyNotEmpty(request, request.Brand, nameof(request.Brand));

private static Result<StartVerificationRequest> VerifyBrandLength(
StartVerificationRequest request) =>
InputValidation
.VerifyLengthLowerOrEqualThan(request, request.Brand, MaxBrandLength, nameof(request.Brand));

private static Result<StartVerificationRequest> VerifyChannelTimeoutHigherThanMinimum(
StartVerificationRequest request) =>
InputValidation
Expand Down

0 comments on commit 11bb4ef

Please sign in to comment.