diff --git a/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeFallbackWorkflows-request.json b/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeFallbackWorkflows-request.json index a3e92d0e8..a0c4ee785 100644 --- a/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeFallbackWorkflows-request.json +++ b/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeFallbackWorkflows-request.json @@ -10,7 +10,8 @@ }, { "channel": "whatsapp", - "to": "447700900000" + "to": "447700900000", + "from": "447700900001" }, { "channel": "voice", diff --git a/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeWhatsAppWorkflow-request.json b/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeWhatsAppWorkflow-request.json index f06a04f05..24e15102b 100644 --- a/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeWhatsAppWorkflow-request.json +++ b/Vonage.Test/VerifyV2/StartVerification/Data/ShouldSerializeWhatsAppWorkflow-request.json @@ -6,7 +6,8 @@ "workflow": [ { "channel": "whatsapp", - "to": "447700900000" + "to": "447700900000", + "from": "447700900001" } ] } \ No newline at end of file diff --git a/Vonage.Test/VerifyV2/StartVerification/E2ETest.cs b/Vonage.Test/VerifyV2/StartVerification/E2ETest.cs index 1e0ce5da5..88b0ccc5a 100644 --- a/Vonage.Test/VerifyV2/StartVerification/E2ETest.cs +++ b/Vonage.Test/VerifyV2/StartVerification/E2ETest.cs @@ -62,7 +62,7 @@ public async Task StartVerificationWithFallbackWorkflows() .Build() .WithBrand("ACME, Inc") .WithWorkflow(WhatsAppInteractiveWorkflow.Parse("447700900000")) - .WithFallbackWorkflow(WhatsAppWorkflow.Parse("447700900000")) + .WithFallbackWorkflow(WhatsAppWorkflow.Parse("447700900000", "447700900001")) .WithFallbackWorkflow(VoiceWorkflow.Parse("447700900000")) .Create()); VerifyResponseBody(result); @@ -89,7 +89,8 @@ public async Task StartWhatsAppInteractiveVerification() public async Task StartWhatsAppVerification() { this.InitializeWireMock(nameof(SerializationTest.ShouldSerializeWhatsAppWorkflow)); - var result = await this.StartVerificationAsyncWithWorkflow(WhatsAppWorkflow.Parse("447700900000")); + var result = + await this.StartVerificationAsyncWithWorkflow(WhatsAppWorkflow.Parse("447700900000", "447700900001")); VerifyResponseBody(result); } diff --git a/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs b/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs index d88b4ffa6..644fb6f5e 100644 --- a/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs +++ b/Vonage.Test/VerifyV2/StartVerification/RequestBuilderTest.cs @@ -78,7 +78,7 @@ public void Create_ShouldReturnFailure_GivenCodeLengthIsLowerThanMinimum() => public void Create_ShouldReturnFailure_GivenOneFallbackWorkflowIsFailure() => BuildBaseRequest() .WithWorkflow(WhatsAppInteractiveWorkflow.Parse("123456789")) - .WithFallbackWorkflow(WhatsAppWorkflow.Parse("123456789")) + .WithFallbackWorkflow(WhatsAppWorkflow.Parse("123456789", "123456789")) .WithFallbackWorkflow( Result.FromFailure(ResultFailure.FromErrorMessage("Random message."))) .Create() @@ -143,7 +143,7 @@ public void Create_ShouldSetCodeLength(int value) => public void Create_ShouldSetFallbackWorkflows() => BuildBaseRequest() .WithWorkflow(WhatsAppInteractiveWorkflow.Parse("123456789")) - .WithFallbackWorkflow(WhatsAppWorkflow.Parse("123456789")) + .WithFallbackWorkflow(WhatsAppWorkflow.Parse("123456789", "123456780")) .WithFallbackWorkflow(VoiceWorkflow.Parse("123456789")) .Create() .Map(request => request.Workflows) @@ -157,7 +157,7 @@ public void Create_ShouldSetFallbackWorkflows() => var fallbackWorkflowOne = workflows[1] as WhatsAppWorkflow? ?? default; fallbackWorkflowOne.Channel.Should().Be("whatsapp"); fallbackWorkflowOne.To.Number.Should().Be("123456789"); - fallbackWorkflowOne.From.Should().BeNone(); + fallbackWorkflowOne.From.Number.Should().Be("123456780"); var fallbackWorkflowTwo = workflows[2] as VoiceWorkflow? ?? default; fallbackWorkflowTwo.Channel.Should().Be("voice"); fallbackWorkflowTwo.To.Number.Should().Be("123456789"); diff --git a/Vonage.Test/VerifyV2/StartVerification/SerializationTest.cs b/Vonage.Test/VerifyV2/StartVerification/SerializationTest.cs index 7af4794c9..c3501493a 100644 --- a/Vonage.Test/VerifyV2/StartVerification/SerializationTest.cs +++ b/Vonage.Test/VerifyV2/StartVerification/SerializationTest.cs @@ -69,7 +69,7 @@ public void ShouldSerializeFallbackWorkflows() => StartVerificationRequest.Build() .WithBrand("ACME, Inc") .WithWorkflow(WhatsAppInteractiveWorkflow.Parse("447700900000")) - .WithFallbackWorkflow(WhatsAppWorkflow.Parse("447700900000")) + .WithFallbackWorkflow(WhatsAppWorkflow.Parse("447700900000", "447700900001")) .WithFallbackWorkflow(VoiceWorkflow.Parse("447700900000")) .Create() .GetStringContent() @@ -145,7 +145,7 @@ public void ShouldSerializeWhatsAppInteractiveWorkflow() => public void ShouldSerializeWhatsAppWorkflow() => StartVerificationRequest.Build() .WithBrand("ACME, Inc") - .WithWorkflow(WhatsAppWorkflow.Parse("447700900000")) + .WithWorkflow(WhatsAppWorkflow.Parse("447700900000", "447700900001")) .Create() .GetStringContent() .Should() diff --git a/Vonage.Test/VerifyV2/StartVerification/Workflows/WhatsAppWorkflowTest.cs b/Vonage.Test/VerifyV2/StartVerification/Workflows/WhatsAppWorkflowTest.cs index 882791c32..bf61162d6 100644 --- a/Vonage.Test/VerifyV2/StartVerification/Workflows/WhatsAppWorkflowTest.cs +++ b/Vonage.Test/VerifyV2/StartVerification/Workflows/WhatsAppWorkflowTest.cs @@ -16,7 +16,8 @@ public class WhatsAppWorkflowTest [Theory] [InlineData("")] [InlineData(" ")] - public void Parse_ShouldReturnFailure_GivenFromIsProvidedButEmpty(string value) => + [InlineData(null)] + public void Parse_ShouldReturnFailure_GivenFromIsNullOrWhitespace(string value) => WhatsAppWorkflow.Parse(ValidToNumber, value) .Should() .BeFailure(ResultFailure.FromErrorMessage("Number cannot be null or whitespace.")); @@ -26,29 +27,18 @@ public void Parse_ShouldReturnFailure_GivenFromIsProvidedButEmpty(string value) [InlineData(" ")] [InlineData(null)] public void Parse_ShouldReturnFailure_GivenToIsNullOrWhitespace(string value) => - WhatsAppWorkflow.Parse(value) + WhatsAppWorkflow.Parse(value, ValidFromNumber) .Should() .BeFailure(ResultFailure.FromErrorMessage("Number cannot be null or whitespace.")); [Fact] public void Parse_ShouldSetWhatsAppWorkflow() => - WhatsAppWorkflow.Parse(ValidToNumber) - .Should() - .BeSuccess(workflow => - { - workflow.Channel.Should().Be(ExpectedChannel); - workflow.To.Number.Should().Be(ValidToNumber); - workflow.From.Should().BeNone(); - }); - - [Fact] - public void Parse_ShouldSetWhatsAppWorkflowWithFrom() => WhatsAppWorkflow.Parse(ValidToNumber, ValidFromNumber) .Should() .BeSuccess(workflow => { workflow.Channel.Should().Be(ExpectedChannel); workflow.To.Number.Should().Be(ValidToNumber); - workflow.From.Map(from => from.Number).Should().BeSome(ValidFromNumber); + workflow.From.Number.Should().Be(ValidFromNumber); }); } \ No newline at end of file diff --git a/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs b/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs index 93a26d5a0..49d16b4fb 100644 --- a/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs +++ b/Vonage/VerifyV2/StartVerification/WhatsApp/WhatsAppWorkflow.cs @@ -10,7 +10,7 @@ namespace Vonage.VerifyV2.StartVerification.WhatsApp; /// public readonly struct WhatsAppWorkflow : IVerificationWorkflow { - private WhatsAppWorkflow(PhoneNumber to, Maybe from) + private WhatsAppWorkflow(PhoneNumber to, PhoneNumber from) { this.To = to; this.From = from; @@ -24,10 +24,9 @@ private WhatsAppWorkflow(PhoneNumber to, Maybe from) /// An optional sender number, in the E.164 format. Don't use a leading + or 00 when entering a phone number, start /// with the country code, for example, 447700900000. /// - [JsonConverter(typeof(MaybeJsonConverter))] - [JsonPropertyOrder(3)] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] - public Maybe From { get; } + [JsonPropertyOrder(2)] + [JsonConverter(typeof(PhoneNumberJsonConverter))] + public PhoneNumber From { get; } /// /// The phone number to contact, in the E.164 format. Don't use a leading + or 00 when entering a phone number, start @@ -37,14 +36,6 @@ private WhatsAppWorkflow(PhoneNumber to, Maybe from) [JsonConverter(typeof(PhoneNumberJsonConverter))] public PhoneNumber To { get; } - /// - /// Parses the input into a WhatsAppWorkflow. - /// - /// The phone number to contact. - /// Success or failure. - public static Result Parse(string to) => - PhoneNumber.Parse(to).Map(phoneNumber => new WhatsAppWorkflow(phoneNumber, Maybe.None)); - /// /// Parses the input into a WhatsAppWorkflow. /// @@ -52,8 +43,8 @@ public static Result Parse(string to) => /// The sender number. /// Success or failure. public static Result Parse(string to, string from) => - PhoneNumber.Parse(to) - .Merge(PhoneNumber.Parse(from), (toNumber, fromNumber) => new WhatsAppWorkflow(toNumber, fromNumber)); + PhoneNumber.Parse(to).Merge(PhoneNumber.Parse(from), + (toNumber, fromNumber) => new WhatsAppWorkflow(toNumber, fromNumber)); /// public string Serialize(IJsonSerializer serializer) => serializer.SerializeObject(this);