-
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 DeleteEvent in Conversations
- Loading branch information
Showing
5 changed files
with
143 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 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Test.Common.Extensions; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Conversations.DeleteEvent; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
public E2ETest() : base(typeof(E2ETest).Namespace) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteEvent() | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v1/conversations/CON-123/events/EVE-123") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.UsingDelete()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)); | ||
await this.Helper.VonageClient.ConversationsClient | ||
.DeleteEventAsync(RequestTest.BuildRequest()) | ||
.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,55 @@ | ||
using Vonage.Common.Monads; | ||
using Vonage.Conversations.DeleteEvent; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Conversations.DeleteEvent; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
private const string ValidConversationId = "CON-123"; | ||
private const string ValidEventId = "EVE-123"; | ||
|
||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
BuildRequest() | ||
.Map(request => request.GetEndpointPath()) | ||
.Should() | ||
.BeSuccess("/v1/conversations/CON-123/events/EVE-123"); | ||
|
||
internal static Result<DeleteEventRequest> BuildRequest() => | ||
DeleteEventRequest.Parse(ValidConversationId, ValidEventId); | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
[InlineData(null)] | ||
public void Parse_ShouldReturnFailure_GivenConversationIdIsEmpty(string invalidId) => | ||
DeleteEventRequest.Parse(invalidId, ValidEventId) | ||
.Should() | ||
.BeParsingFailure("ConversationId cannot be null or whitespace."); | ||
|
||
[Theory] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
[InlineData(null)] | ||
public void Parse_ShouldReturnFailure_GivenEventIdIsEmpty(string invalidId) => | ||
DeleteEventRequest.Parse(ValidConversationId, invalidId) | ||
.Should() | ||
.BeParsingFailure("EventId cannot be null or whitespace."); | ||
|
||
[Fact] | ||
public void Parse_ShouldSetConversationId() => | ||
BuildRequest() | ||
.Map(request => request.ConversationId) | ||
.Should() | ||
.BeSuccess("CON-123"); | ||
|
||
[Fact] | ||
public void Parse_ShouldSetEventId() => | ||
BuildRequest() | ||
.Map(request => request.EventId) | ||
.Should() | ||
.BeSuccess("EVE-123"); | ||
} |
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,46 @@ | ||
using System.Net.Http; | ||
using Vonage.Common.Client; | ||
using Vonage.Common.Monads; | ||
using Vonage.Common.Validation; | ||
|
||
namespace Vonage.Conversations.DeleteEvent; | ||
|
||
/// <inheritdoc /> | ||
public readonly struct DeleteEventRequest : IVonageRequest | ||
{ | ||
/// <summary> | ||
/// The conversation Id. | ||
/// </summary> | ||
public string ConversationId { get; private init; } | ||
|
||
/// <summary> | ||
/// The event Id. | ||
/// </summary> | ||
public string EventId { get; private init; } | ||
|
||
/// <inheritdoc /> | ||
public HttpRequestMessage BuildRequestMessage() => VonageRequestBuilder | ||
.Initialize(HttpMethod.Delete, this.GetEndpointPath()) | ||
.Build(); | ||
|
||
/// <inheritdoc /> | ||
public string GetEndpointPath() => $"/v1/conversations/{this.ConversationId}/events/{this.EventId}"; | ||
|
||
/// <summary> | ||
/// Parses the input into a DeleteEventRequest. | ||
/// </summary> | ||
/// <param name="conversationId">The conversation Id.</param> | ||
/// <param name="eventId">The event Id.</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<DeleteEventRequest> Parse(string conversationId, string eventId) => | ||
Result<DeleteEventRequest> | ||
.FromSuccess(new DeleteEventRequest {ConversationId = conversationId, EventId = eventId}) | ||
.Map(InputEvaluation<DeleteEventRequest>.Evaluate) | ||
.Bind(evaluation => evaluation.WithRules(VerifyConversationId, VerifyEventId)); | ||
|
||
private static Result<DeleteEventRequest> VerifyConversationId(DeleteEventRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.ConversationId, nameof(ConversationId)); | ||
|
||
private static Result<DeleteEventRequest> VerifyEventId(DeleteEventRequest request) => | ||
InputValidation.VerifyNotEmpty(request, request.EventId, nameof(EventId)); | ||
} |
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