-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement GetTemplate for VerifyV2
- Loading branch information
Showing
8 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
Vonage.Test/VerifyV2/GetTemplate/Data/ShouldDeserialize200-response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Template>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(VerifyExpectedResponse); | ||
|
||
internal static void VerifyExpectedResponse(Template response) => | ||
response.Should().Be(new Template(new Guid("8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9"), "my-template", true, | ||
new TemplateLinks( | ||
new HalLink(new Uri("https://api.nexmo.com/v2/verify/templates/8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9")), | ||
new HalLink(new Uri( | ||
"https://api.nexmo.com/v2/verify/templates/8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9/template_fragments"))))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#region | ||
using System; | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Validation; | ||
#endregion | ||
|
||
namespace Vonage.VerifyV2.GetTemplate; | ||
|
||
/// <inheritdoc /> | ||
public readonly struct GetTemplateRequest : IVonageRequest | ||
{ | ||
/// <summary> | ||
/// ID of the template. | ||
/// </summary> | ||
public Guid TemplateId { get; private init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder | ||
.Initialize(HttpMethod.Get, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/v2/verify/templates/{this.TemplateId}"; | ||
|
||
/// <summary> | ||
/// Parses the input into a GetTemplateRequest. | ||
/// </summary> | ||
/// <param name="templateId">The template identifier.</param> | ||
/// <returns>A success state with the request if the parsing succeeded. A failure state with an error if it failed.</returns> | ||
public static Result<GetTemplateRequest> Parse(Guid templateId) => | ||
Result<GetTemplateRequest> | ||
.FromSuccess(new GetTemplateRequest {TemplateId = templateId}) | ||
.Map(InputEvaluation<GetTemplateRequest>.Evaluate) | ||
.Bind(evaluation => evaluation.WithRules(VerifyRequestId)); | ||
|
||
private static Result<GetTemplateRequest> VerifyRequestId(GetTemplateRequest templateRequest) => | ||
InputValidation.VerifyNotEmpty(templateRequest, templateRequest.TemplateId, nameof(TemplateId)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters