-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement DeleteTemplate for VerifyV2
- Loading branch information
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
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,29 @@ | ||
#region | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Test.Common.Extensions; | ||
using Vonage.VerifyV2.DeleteTemplate; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
#endregion | ||
|
||
namespace Vonage.Test.VerifyV2.DeleteTemplate; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
[Fact] | ||
public async Task CancelVerification() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v2/verify/templates/68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); | ||
await this.Helper.VonageClient.VerifyV2Client.DeleteTemplateAsync( | ||
DeleteTemplateRequest.Parse(Guid.Parse("68c2b32e-55ba-4a8e-b3fa-43b3ae6cd1fb"))) | ||
.Should() | ||
.BeSuccessAsync(); | ||
} | ||
} |
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.DeleteTemplate; | ||
using Xunit; | ||
#endregion | ||
|
||
namespace Vonage.Test.VerifyV2.DeleteTemplate; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
DeleteTemplateRequest.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() => | ||
DeleteTemplateRequest.Parse(Guid.Empty) | ||
.Should() | ||
.BeParsingFailure("TemplateId cannot be empty."); | ||
|
||
[Fact] | ||
public void Parse_ShouldReturnSuccess() => | ||
DeleteTemplateRequest.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,40 @@ | ||
#region | ||
using System; | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Validation; | ||
#endregion | ||
|
||
namespace Vonage.VerifyV2.DeleteTemplate; | ||
|
||
/// <inheritdoc /> | ||
public readonly struct DeleteTemplateRequest : IVonageRequest | ||
{ | ||
/// <summary> | ||
/// ID of the template. | ||
/// </summary> | ||
public Guid TemplateId { get; private init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder | ||
.Initialize(HttpMethod.Delete, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/v2/verify/templates/{this.TemplateId}"; | ||
|
||
/// <summary> | ||
/// Parses the input into a DeleteRequest. | ||
/// </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<DeleteTemplateRequest> Parse(Guid templateId) => | ||
Result<DeleteTemplateRequest> | ||
.FromSuccess(new DeleteTemplateRequest {TemplateId = templateId}) | ||
.Map(InputEvaluation<DeleteTemplateRequest>.Evaluate) | ||
.Bind(evaluation => evaluation.WithRules(VerifyRequestId)); | ||
|
||
private static Result<DeleteTemplateRequest> VerifyRequestId(DeleteTemplateRequest 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