Skip to content

Commit

Permalink
feat: implement DeleteTemplate for VerifyV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Sep 10, 2024
1 parent 7a459d3 commit 5d8f806
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Vonage.Test/VerifyV2/DeleteTemplate/E2ETest.cs
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();
}
}
32 changes: 32 additions & 0 deletions Vonage.Test/VerifyV2/DeleteTemplate/RequestTest.cs
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"));
}
40 changes: 40 additions & 0 deletions Vonage/VerifyV2/DeleteTemplate/DeleteTemplateRequest.cs
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));
}
8 changes: 8 additions & 0 deletions Vonage/VerifyV2/IVerifyV2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Vonage.Common.Monads;
using Vonage.VerifyV2.Cancel;
using Vonage.VerifyV2.CreateTemplate;
using Vonage.VerifyV2.DeleteTemplate;
using Vonage.VerifyV2.NextWorkflow;
using Vonage.VerifyV2.StartVerification;
using Vonage.VerifyV2.VerifyCode;
Expand Down Expand Up @@ -49,4 +50,11 @@ public interface IVerifyV2Client
/// <param name="request">The request.</param>
/// <returns>Success or Failure.</returns>
Task<Result<Template>> CreateTemplateAsync(Result<CreateTemplateRequest> request);

/// <summary>
/// Deletes a template.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Success or Failure.</returns>
Task<Result<Unit>> DeleteTemplateAsync(Result<DeleteTemplateRequest> request);
}
5 changes: 5 additions & 0 deletions Vonage/VerifyV2/VerifyV2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Vonage.Serialization;
using Vonage.VerifyV2.Cancel;
using Vonage.VerifyV2.CreateTemplate;
using Vonage.VerifyV2.DeleteTemplate;
using Vonage.VerifyV2.NextWorkflow;
using Vonage.VerifyV2.StartVerification;
using Vonage.VerifyV2.VerifyCode;
Expand Down Expand Up @@ -42,4 +43,8 @@ public Task<Result<Unit>> VerifyCodeAsync(Result<VerifyCodeRequest> request) =>
/// <inheritdoc />
public Task<Result<Template>> CreateTemplateAsync(Result<CreateTemplateRequest> request) =>
this.vonageClient.SendWithResponseAsync<CreateTemplateRequest, Template>(request);

/// <inheritdoc />
public Task<Result<Unit>> DeleteTemplateAsync(Result<DeleteTemplateRequest> request) =>
this.vonageClient.SendAsync(request);
}

0 comments on commit 5d8f806

Please sign in to comment.