From e60d8de6a978a598acb16b03ebe0365c53cac3c5 Mon Sep 17 00:00:00 2001 From: Guillaume Faas Date: Wed, 20 Dec 2023 07:33:08 +0100 Subject: [PATCH] feat: implement UpdateConversation --- .../UpdateConversation/E2ETest.cs | 44 +++++++++++++++++++ .../UpdateConversation/SerializationTest.cs | 4 +- Vonage/Conversations/ConversationsClient.cs | 12 +++++ .../CreateConversationRequest.cs | 6 +++ .../UpdateConversationRequest.cs | 7 +++ 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 Vonage.Test.Unit/Conversations/UpdateConversation/E2ETest.cs diff --git a/Vonage.Test.Unit/Conversations/UpdateConversation/E2ETest.cs b/Vonage.Test.Unit/Conversations/UpdateConversation/E2ETest.cs new file mode 100644 index 000000000..7b004632e --- /dev/null +++ b/Vonage.Test.Unit/Conversations/UpdateConversation/E2ETest.cs @@ -0,0 +1,44 @@ +using System.Net; +using System.Threading.Tasks; +using Vonage.Common.Monads; +using Vonage.Common.Test.Extensions; +using Vonage.Conversations.UpdateConversation; +using WireMock.ResponseBuilders; +using Xunit; + +namespace Vonage.Test.Unit.Conversations.UpdateConversation +{ + [Trait("Category", "E2E")] + public class E2ETest : E2EBase + { + public E2ETest() : base(typeof(E2ETest).Namespace) + { + } + + [Fact] + public Task UpdateConversation_WithEmptyRequest() => + this.UpdateConversationAsync( + this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerializeEmpty)), + SerializationTest.BuildEmptyRequest()); + + [Fact] + public Task UpdateConversation_WithRequest() => + this.UpdateConversationAsync(this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerialize)), + SerializationTest.BuildRequest()); + + private async Task UpdateConversationAsync(string jsonRequest, Result request) + { + this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() + .WithPath("/v1/conversations/CON-1234") + .WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) + .WithBody(jsonRequest) + .UsingPut()) + .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) + .WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); + await this.Helper.VonageClient.ConversationsClient + .UpdateConversationAsync(request) + .Should() + .BeSuccessAsync(ConversationTests.VerifyExpectedResponse); + } + } +} \ No newline at end of file diff --git a/Vonage.Test.Unit/Conversations/UpdateConversation/SerializationTest.cs b/Vonage.Test.Unit/Conversations/UpdateConversation/SerializationTest.cs index 2e4fb6cad..e693ebd3e 100644 --- a/Vonage.Test.Unit/Conversations/UpdateConversation/SerializationTest.cs +++ b/Vonage.Test.Unit/Conversations/UpdateConversation/SerializationTest.cs @@ -43,7 +43,7 @@ public void ShouldSerializeEmpty() => BuildEmptyRequest() internal static Result BuildRequest() => UpdateConversationRequest.Build() - .WithConversationId("not relevant") + .WithConversationId("CON-1234") .WithName("customer_chat") .WithDisplayName("Customer Chat") .WithImageUrl(new Uri("https://example.com/image.png")) @@ -64,7 +64,7 @@ internal static Result BuildRequest() => internal static Result BuildEmptyRequest() => UpdateConversationRequest.Build() - .WithConversationId("not relevant") + .WithConversationId("CON-1234") .Create(); } } \ No newline at end of file diff --git a/Vonage/Conversations/ConversationsClient.cs b/Vonage/Conversations/ConversationsClient.cs index 6bc819948..cb7b9d4fd 100644 --- a/Vonage/Conversations/ConversationsClient.cs +++ b/Vonage/Conversations/ConversationsClient.cs @@ -5,6 +5,7 @@ using Vonage.Conversations.DeleteConversation; using Vonage.Conversations.GetConversation; using Vonage.Conversations.GetConversations; +using Vonage.Conversations.UpdateConversation; using Vonage.Serialization; namespace Vonage.Conversations; @@ -41,6 +42,13 @@ public interface IConversationsClient /// The request. /// Success or Failure. Task> GetConversationsAsync(Result request); + + /// + /// Updates a conversation. + /// + /// The request. + /// Success or Failure. + Task> UpdateConversationAsync(Result request); } internal class ConversationsClient : IConversationsClient @@ -70,4 +78,8 @@ public Task> GetConversationAsync(Result public Task> GetConversationsAsync(Result request) => this.vonageClient.SendWithResponseAsync(request); + + /// + public Task> UpdateConversationAsync(Result request) => + this.vonageClient.SendWithResponseAsync(request); } \ No newline at end of file diff --git a/Vonage/Conversations/CreateConversation/CreateConversationRequest.cs b/Vonage/Conversations/CreateConversation/CreateConversationRequest.cs index 57a49d378..8c5af2599 100644 --- a/Vonage/Conversations/CreateConversation/CreateConversationRequest.cs +++ b/Vonage/Conversations/CreateConversation/CreateConversationRequest.cs @@ -13,26 +13,32 @@ namespace Vonage.Conversations.CreateConversation; public readonly struct CreateConversationRequest : IVonageRequest { /// + /// Conversation callback /// public Maybe Callback { get; internal init; } /// + /// The public facing name of the conversation /// public Maybe DisplayName { get; internal init; } /// + /// An image URL that you associate with the conversation /// public Maybe ImageUrl { get; internal init; } /// + /// Your internal conversation name. Must be unique /// public Maybe Name { get; internal init; } /// + /// Conversation numbers /// public Maybe> Numbers { get; internal init; } /// + /// Conversation properties /// public Maybe Properties { get; internal init; } diff --git a/Vonage/Conversations/UpdateConversation/UpdateConversationRequest.cs b/Vonage/Conversations/UpdateConversation/UpdateConversationRequest.cs index 58d47d242..69b2c4796 100644 --- a/Vonage/Conversations/UpdateConversation/UpdateConversationRequest.cs +++ b/Vonage/Conversations/UpdateConversation/UpdateConversationRequest.cs @@ -13,30 +13,37 @@ namespace Vonage.Conversations.UpdateConversation; public readonly struct UpdateConversationRequest : IVonageRequest { /// + /// Conversation callback /// public Maybe Callback { get; internal init; } /// + /// Conversation ID /// public string ConversationId { get; internal init; } /// + /// The public facing name of the conversation /// public Maybe DisplayName { get; internal init; } /// + /// An image URL that you associate with the conversation /// public Maybe ImageUrl { get; internal init; } /// + /// Your internal conversation name. Must be unique /// public Maybe Name { get; internal init; } /// + /// Conversation numbers /// public Maybe> Numbers { get; internal init; } /// + /// Conversation properties /// public Maybe Properties { get; internal init; }