Skip to content

Commit

Permalink
feat: implement UpdateConversation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Dec 20, 2023
1 parent 53a7ee9 commit e60d8de
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
44 changes: 44 additions & 0 deletions Vonage.Test.Unit/Conversations/UpdateConversation/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -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<UpdateConversationRequest> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ShouldSerializeEmpty() => BuildEmptyRequest()

internal static Result<UpdateConversationRequest> BuildRequest() =>
UpdateConversationRequest.Build()
.WithConversationId("not relevant")
.WithConversationId("CON-1234")
.WithName("customer_chat")
.WithDisplayName("Customer Chat")
.WithImageUrl(new Uri("https://example.com/image.png"))
Expand All @@ -64,7 +64,7 @@ internal static Result<UpdateConversationRequest> BuildRequest() =>

internal static Result<UpdateConversationRequest> BuildEmptyRequest() =>
UpdateConversationRequest.Build()
.WithConversationId("not relevant")
.WithConversationId("CON-1234")
.Create();
}
}
12 changes: 12 additions & 0 deletions Vonage/Conversations/ConversationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +42,13 @@ public interface IConversationsClient
/// <param name="request">The request.</param>
/// <returns>Success or Failure.</returns>
Task<Result<GetConversationsResponse>> GetConversationsAsync(Result<GetConversationsRequest> request);

/// <summary>
/// Updates a conversation.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>Success or Failure.</returns>
Task<Result<Conversation>> UpdateConversationAsync(Result<UpdateConversationRequest> request);
}

internal class ConversationsClient : IConversationsClient
Expand Down Expand Up @@ -70,4 +78,8 @@ public Task<Result<Conversation>> GetConversationAsync(Result<GetConversationReq
/// <inheritdoc />
public Task<Result<GetConversationsResponse>> GetConversationsAsync(Result<GetConversationsRequest> request) =>
this.vonageClient.SendWithResponseAsync<GetConversationsRequest, GetConversationsResponse>(request);

/// <inheritdoc />
public Task<Result<Conversation>> UpdateConversationAsync(Result<UpdateConversationRequest> request) =>
this.vonageClient.SendWithResponseAsync<UpdateConversationRequest, Conversation>(request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,32 @@ namespace Vonage.Conversations.CreateConversation;
public readonly struct CreateConversationRequest : IVonageRequest
{
/// <summary>
/// Conversation callback
/// </summary>
public Maybe<Callback> Callback { get; internal init; }

/// <summary>
/// The public facing name of the conversation
/// </summary>
public Maybe<string> DisplayName { get; internal init; }

/// <summary>
/// An image URL that you associate with the conversation
/// </summary>
public Maybe<Uri> ImageUrl { get; internal init; }

/// <summary>
/// Your internal conversation name. Must be unique
/// </summary>
public Maybe<string> Name { get; internal init; }

/// <summary>
/// Conversation numbers
/// </summary>
public Maybe<IEnumerable<INumber>> Numbers { get; internal init; }

/// <summary>
/// Conversation properties
/// </summary>
public Maybe<Properties> Properties { get; internal init; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,37 @@ namespace Vonage.Conversations.UpdateConversation;
public readonly struct UpdateConversationRequest : IVonageRequest
{
/// <summary>
/// Conversation callback
/// </summary>
public Maybe<Callback> Callback { get; internal init; }

/// <summary>
/// Conversation ID
/// </summary>
public string ConversationId { get; internal init; }

/// <summary>
/// The public facing name of the conversation
/// </summary>
public Maybe<string> DisplayName { get; internal init; }

/// <summary>
/// An image URL that you associate with the conversation
/// </summary>
public Maybe<Uri> ImageUrl { get; internal init; }

/// <summary>
/// Your internal conversation name. Must be unique
/// </summary>
public Maybe<string> Name { get; internal init; }

/// <summary>
/// Conversation numbers
/// </summary>
public Maybe<IEnumerable<INumber>> Numbers { get; internal init; }

/// <summary>
/// Conversation properties
/// </summary>
public Maybe<Properties> Properties { get; internal init; }

Expand Down

0 comments on commit e60d8de

Please sign in to comment.