From ce23ccdbdcc7bb18b9eb94f7cc020237320e6864 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 11 Sep 2024 14:29:33 +0200 Subject: [PATCH] feat: implement GetTemplate for VerifyV2 --- .../Data/ShouldDeserialize200-response.json | 13 ++++++ Vonage.Test/VerifyV2/GetTemplate/E2ETest.cs | 35 ++++++++++++++++ .../VerifyV2/GetTemplate/RequestTest.cs | 32 +++++++++++++++ .../VerifyV2/GetTemplate/SerializationTest.cs | 34 ++++++++++++++++ Vonage.Test/Vonage.Test.csproj | 3 ++ .../GetTemplate/GetTemplateRequest.cs | 40 +++++++++++++++++++ Vonage/VerifyV2/IVerifyV2Client.cs | 8 ++++ Vonage/VerifyV2/VerifyV2Client.cs | 5 +++ 8 files changed, 170 insertions(+) create mode 100644 Vonage.Test/VerifyV2/GetTemplate/Data/ShouldDeserialize200-response.json create mode 100644 Vonage.Test/VerifyV2/GetTemplate/E2ETest.cs create mode 100644 Vonage.Test/VerifyV2/GetTemplate/RequestTest.cs create mode 100644 Vonage.Test/VerifyV2/GetTemplate/SerializationTest.cs create mode 100644 Vonage/VerifyV2/GetTemplate/GetTemplateRequest.cs diff --git a/Vonage.Test/VerifyV2/GetTemplate/Data/ShouldDeserialize200-response.json b/Vonage.Test/VerifyV2/GetTemplate/Data/ShouldDeserialize200-response.json new file mode 100644 index 00000000..af4336ce --- /dev/null +++ b/Vonage.Test/VerifyV2/GetTemplate/Data/ShouldDeserialize200-response.json @@ -0,0 +1,13 @@ +{ + "template_id": "8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9", + "name": "my-template", + "is_default": true, + "_links": { + "self": { + "href": "https://api.nexmo.com/v2/verify/templates/8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9" + }, + "fragments": { + "href": "https://api.nexmo.com/v2/verify/templates/8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9/template_fragments" + } + } +} \ No newline at end of file diff --git a/Vonage.Test/VerifyV2/GetTemplate/E2ETest.cs b/Vonage.Test/VerifyV2/GetTemplate/E2ETest.cs new file mode 100644 index 00000000..befac238 --- /dev/null +++ b/Vonage.Test/VerifyV2/GetTemplate/E2ETest.cs @@ -0,0 +1,35 @@ +#region +using System; +using System.Net; +using System.Threading.Tasks; +using Vonage.Test.Common.Extensions; +using Vonage.VerifyV2.GetTemplate; +using WireMock.ResponseBuilders; +using Xunit; +#endregion + +namespace Vonage.Test.VerifyV2.GetTemplate; + +[Trait("Category", "E2E")] +public class E2ETest : E2EBase +{ + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public async Task GetTemplate() + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath("/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb") + .WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) + .UsingGet()) + .RespondWith(Response.Create() + .WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.VerifyV2Client + .GetTemplateAsync(GetTemplateRequest.Parse(new Guid("68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb"))) + .Should() + .BeSuccessAsync(SerializationTest.VerifyExpectedResponse); + } +} \ No newline at end of file diff --git a/Vonage.Test/VerifyV2/GetTemplate/RequestTest.cs b/Vonage.Test/VerifyV2/GetTemplate/RequestTest.cs new file mode 100644 index 00000000..694891e3 --- /dev/null +++ b/Vonage.Test/VerifyV2/GetTemplate/RequestTest.cs @@ -0,0 +1,32 @@ +#region +using System; +using Vonage.Test.Common.Extensions; +using Vonage.VerifyV2.GetTemplate; +using Xunit; +#endregion + +namespace Vonage.Test.VerifyV2.GetTemplate; + +[Trait("Category", "Request")] +public class RequestTest +{ + [Fact] + public void GetEndpointPath_ShouldReturnApiEndpoint() => + GetTemplateRequest.Parse(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287")) + .Map(request => request.GetEndpointPath()) + .Should() + .BeSuccess("/v2/verify/templates/f3a065af-ac5a-47a4-8dfe-819561a7a287"); + + [Fact] + public void Parse_ShouldReturnFailure_GivenRequestIsEmpty() => + GetTemplateRequest.Parse(Guid.Empty) + .Should() + .BeParsingFailure("TemplateId cannot be empty."); + + [Fact] + public void Parse_ShouldReturnSuccess() => + GetTemplateRequest.Parse(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287")) + .Map(request => request.TemplateId) + .Should() + .BeSuccess(new Guid("f3a065af-ac5a-47a4-8dfe-819561a7a287")); +} \ No newline at end of file diff --git a/Vonage.Test/VerifyV2/GetTemplate/SerializationTest.cs b/Vonage.Test/VerifyV2/GetTemplate/SerializationTest.cs new file mode 100644 index 00000000..31b712e9 --- /dev/null +++ b/Vonage.Test/VerifyV2/GetTemplate/SerializationTest.cs @@ -0,0 +1,34 @@ +#region +using System; +using FluentAssertions; +using Vonage.Common; +using Vonage.Serialization; +using Vonage.Test.Common; +using Vonage.Test.Common.Extensions; +using Vonage.VerifyV2; +using Xunit; +#endregion + +namespace Vonage.Test.VerifyV2.GetTemplate; + +[Trait("Category", "Serialization")] +public class SerializationTest +{ + private readonly SerializationTestHelper helper = new SerializationTestHelper( + typeof(SerializationTest).Namespace, + JsonSerializerBuilder.BuildWithSnakeCase()); + + [Fact] + public void ShouldDeserialize200() => + this.helper.Serializer + .DeserializeObject