Skip to content

Commit

Permalink
feat: change minimum channel timeout from 60s to 15s for VerifyV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jul 19, 2024
1 parent 358e2cf commit f1766a2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
71 changes: 44 additions & 27 deletions Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using FluentAssertions;
#region
using FluentAssertions;
using FsCheck;
using FsCheck.Xunit;
using Vonage.Common.Failures;
using Vonage.Common.Monads;
using Vonage.Test.Common.Extensions;
Expand All @@ -10,6 +13,7 @@
using Vonage.VerifyV2.StartVerification.WhatsApp;
using Vonage.VerifyV2.StartVerification.WhatsAppInteractive;
using Xunit;
#endregion

namespace Vonage.Test.VerifyV2.StartVerification;

Expand Down Expand Up @@ -50,21 +54,25 @@ public void Create_ShouldReturnFailure_GivenBrandExceeds16Characters() =>

[Fact]
public void Create_ShouldReturnFailure_GivenChannelTimeoutIsHigherThanMaximum() =>
BuildBaseRequest()
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithChannelTimeout(901)
.Create()
.Should()
.BeParsingFailure("ChannelTimeout cannot be higher than 900.");

[Fact]
public void Create_ShouldReturnFailure_GivenChannelTimeoutIsLowerThanMinimum() =>
BuildBaseRequest()
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithChannelTimeout(59)
.Create()
.Should()
.BeParsingFailure("ChannelTimeout cannot be lower than 60.");
Prop.ForAll(
GetChannelTimeoutsAboveMaximum(),
invalidTimeout => BuildBaseRequest()
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithChannelTimeout(invalidTimeout)
.Create()
.Should()
.BeParsingFailure("ChannelTimeout cannot be higher than 900."));

[Property]
public Property Create_ShouldReturnFailure_GivenChannelTimeoutIsLowerThanMinimum() =>
Prop.ForAll(
GetChannelTimeoutsBelowMinimum(),
invalidTimeout => BuildBaseRequest()
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithChannelTimeout(invalidTimeout)
.Create()
.Should()
.BeParsingFailure("ChannelTimeout cannot be lower than 15."));

[Fact]
public void Create_ShouldReturnFailure_GivenCodeLengthIsHigherThanMaximum() =>
Expand Down Expand Up @@ -106,17 +114,26 @@ public void Create_ShouldSetBrand() =>
.Should()
.BeSuccess("Brand Custom 123");

[Theory]
[InlineData(60)]
[InlineData(900)]
public void Create_ShouldSetChannelTimeout(int value) =>
BuildBaseRequest()
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithChannelTimeout(value)
.Create()
.Map(request => request.ChannelTimeout)
.Should()
.BeSuccess(value);
[Property]
public Property Create_ShouldSetChannelTimeout() =>
Prop.ForAll(
GetValidChannelTimeouts(),
validTimeout => BuildBaseRequest()
.WithWorkflow(EmailWorkflow.Parse(ValidEmail))
.WithChannelTimeout(validTimeout)
.Create()
.Map(request => request.ChannelTimeout)
.Should()
.BeSuccess(validTimeout));

private static Arbitrary<int> GetChannelTimeoutsAboveMaximum() =>
Gen.Choose(901, int.MaxValue).ToArbitrary();

private static Arbitrary<int> GetChannelTimeoutsBelowMinimum() =>
Gen.Choose(14, -int.MaxValue).ToArbitrary();

private static Arbitrary<int> GetValidChannelTimeouts() =>
Gen.Choose(15, 900).ToArbitrary();

[Fact]
public void Create_ShouldSetClientReference() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#region
using System.Collections.Generic;
using Vonage.Common.Client;
using Vonage.Common.Failures;
using Vonage.Common.Monads;
using Vonage.Common.Validation;
#endregion

namespace Vonage.VerifyV2.StartVerification;

Expand All @@ -12,6 +14,12 @@ internal class StartVerificationRequestBuilder :
IBuilderForWorkflow
{
private const int MaxBrandLength = 16;

private const int MinChannelTimeout = 15;
private const int MaxChannelTimeout = 900;

private const int MinCodeLength = 4;
private const int MaxCodeLength = 10;
private readonly List<IVerificationWorkflow> workflows = new List<IVerificationWorkflow>();
private string brand;
private int channelTimeout = 300;
Expand Down Expand Up @@ -138,22 +146,23 @@ private static Result<StartVerificationRequest> VerifyBrandLength(
private static Result<StartVerificationRequest> VerifyChannelTimeoutHigherThanMinimum(
StartVerificationRequest request) =>
InputValidation
.VerifyHigherOrEqualThan(request, request.ChannelTimeout, 60, nameof(request.ChannelTimeout));
.VerifyHigherOrEqualThan(request, request.ChannelTimeout, MinChannelTimeout,
nameof(request.ChannelTimeout));

private static Result<StartVerificationRequest> VerifyChannelTimeoutLowerThanMaximum(
StartVerificationRequest request) =>
InputValidation
.VerifyLowerOrEqualThan(request, request.ChannelTimeout, 900, nameof(request.ChannelTimeout));
.VerifyLowerOrEqualThan(request, request.ChannelTimeout, MaxChannelTimeout, nameof(request.ChannelTimeout));

private static Result<StartVerificationRequest> VerifyCodeLengthHigherThanMinimum(
StartVerificationRequest request) =>
InputValidation
.VerifyHigherOrEqualThan(request, request.CodeLength, 4, nameof(request.CodeLength));
.VerifyHigherOrEqualThan(request, request.CodeLength, MinCodeLength, nameof(request.CodeLength));

private static Result<StartVerificationRequest> VerifyCodeLengthLowerThanMaximum(
StartVerificationRequest request) =>
InputValidation
.VerifyLowerOrEqualThan(request, request.CodeLength, 10, nameof(request.CodeLength));
.VerifyLowerOrEqualThan(request, request.CodeLength, MaxCodeLength, nameof(request.CodeLength));
}

/// <summary>
Expand Down

0 comments on commit f1766a2

Please sign in to comment.