Skip to content

Commit

Permalink
feat: implement GetMembers in Conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed May 29, 2024
1 parent d0b98ec commit ffe0c0a
Show file tree
Hide file tree
Showing 16 changed files with 557 additions and 40 deletions.
10 changes: 5 additions & 5 deletions Vonage.Test/Conversations/GetConversations/E2ETest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class E2ETest : E2EBase
public E2ETest() : base(typeof(E2ETest).Namespace)
{
}

[Fact]
public async Task GetConversations()
{
Expand All @@ -40,7 +40,7 @@ await this.Helper.VonageClient.ConversationsClient
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}

[Fact]
public async Task GetConversationsFromHalLink()
{
Expand All @@ -56,13 +56,13 @@ public async Task GetConversationsFromHalLink()
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.ConversationsClient
.GetConversationsAsync(new GetConversationsHalLink(new Uri(
"https://api.nexmo.com/v1/users?order=desc&page_size=50&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D&date_start=2023-12-18T09%3A56%3A08Z&date_end=2023-12-18T10%3A56%3A08Z"))
.GetConversationsAsync(new GetMembersHalLink(new Uri(
"https://api.nexmo.com/v1/conversations?order=desc&page_size=50&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D&date_start=2023-12-18T09%3A56%3A08Z&date_end=2023-12-18T10%3A56%3A08Z"))
.BuildRequest())
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}

[Fact]
public async Task GetConversationsWithDefaultRequest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
namespace Vonage.Test.Conversations.GetConversations;

[Trait("Category", "Request")]
public class GetConversationsHalLinkTest
public class GetMembersHalLinkTest
{
[Fact]
public void BuildRequestForPrevious_ShouldReturnSuccess() =>
new GetConversationsHalLink(new Uri("https://api.nexmo.com/v1/users?order=desc&page_size=10"))
new GetMembersHalLink(new Uri("https://api.nexmo.com/v1/users?order=desc&page_size=10"))
.BuildRequest()
.Should()
.BeSuccess(new GetConversationsRequest
Expand All @@ -24,28 +24,28 @@ public void BuildRequestForPrevious_ShouldReturnSuccess() =>
PageSize = 10,
Order = FetchOrder.Descending,
});

[Fact]
public void BuildRequestForPrevious_ShouldReturnSuccess_WithCursor() =>
new GetConversationsHalLink(new Uri(
new GetMembersHalLink(new Uri(
"https://api.nexmo.com/v1/users?order=desc&page_size=10&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D"))
.BuildRequest()
.Map(request => request.Cursor)
.Should()
.BeSuccess("7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg=");

[Fact]
public void BuildRequestForPrevious_ShouldReturnSuccess_WithEndDate() =>
new GetConversationsHalLink(new Uri(
new GetMembersHalLink(new Uri(
"https://api.nexmo.com/v1/users?order=desc&page_size=10&date_end=2023-12-18T10%3A56%3A08Z"))
.BuildRequest()
.Map(request => request.EndDate)
.Should()
.BeSuccess(DateTimeOffset.Parse("2023-12-18T10:56:08Z", CultureInfo.InvariantCulture));

[Fact]
public void BuildRequestForPrevious_ShouldReturnSuccess_WithStartDate() =>
new GetConversationsHalLink(new Uri(
new GetMembersHalLink(new Uri(
"https://api.nexmo.com/v1/users?order=desc&page_size=10&date_start=2023-12-18T09%3A56%3A08Z"))
.BuildRequest()
.Map(request => request.StartDate)
Expand Down
31 changes: 17 additions & 14 deletions Vonage.Test/Conversations/GetConversations/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Build_ShouldHaveDefaultOrder() =>
.Map(request => request.Order)
.Should()
.BeSuccess(FetchOrder.Ascending);

[Fact]
public void Build_ShouldHaveDefaultPageSize() =>
GetConversationsRequest
Expand All @@ -28,7 +28,7 @@ public void Build_ShouldHaveDefaultPageSize() =>
.Map(request => request.PageSize)
.Should()
.BeSuccess(10);

[Fact]
public void Build_ShouldHaveNoDefaultCursor() =>
GetConversationsRequest
Expand All @@ -37,7 +37,7 @@ public void Build_ShouldHaveNoDefaultCursor() =>
.Map(request => request.Cursor)
.Should()
.BeSuccess(Maybe<string>.None);

[Fact]
public void Build_ShouldHaveNoDefaultEndDate() =>
GetConversationsRequest
Expand All @@ -46,7 +46,7 @@ public void Build_ShouldHaveNoDefaultEndDate() =>
.Map(request => request.EndDate)
.Should()
.BeSuccess(Maybe<DateTimeOffset>.None);

[Fact]
public void Build_ShouldHaveNoDefaultStartDate() =>
GetConversationsRequest
Expand All @@ -55,7 +55,7 @@ public void Build_ShouldHaveNoDefaultStartDate() =>
.Map(request => request.StartDate)
.Should()
.BeSuccess(Maybe<DateTimeOffset>.None);

[Fact]
public void Build_ShouldReturnFailure_GivenPageSizeIsHigherThanOneHundred() =>
GetConversationsRequest
Expand All @@ -64,7 +64,7 @@ public void Build_ShouldReturnFailure_GivenPageSizeIsHigherThanOneHundred() =>
.Create()
.Should()
.BeParsingFailure("PageSize cannot be higher than 100.");

[Fact]
public void Build_ShouldReturnFailure_GivenPageSizeIsLowerThanOne() =>
GetConversationsRequest
Expand All @@ -73,7 +73,7 @@ public void Build_ShouldReturnFailure_GivenPageSizeIsLowerThanOne() =>
.Create()
.Should()
.BeParsingFailure("PageSize cannot be lower than 1.");

[Fact]
public void Build_ShouldSetEndDate() =>
GetConversationsRequest
Expand All @@ -83,7 +83,7 @@ public void Build_ShouldSetEndDate() =>
.Map(request => request.EndDate)
.Should()
.BeSuccess(DateTimeOffset.Parse("2018-01-01 10:00:00", CultureInfo.InvariantCulture));

[Fact]
public void Build_ShouldSetOrder() =>
GetConversationsRequest
Expand All @@ -93,17 +93,20 @@ public void Build_ShouldSetOrder() =>
.Map(request => request.Order)
.Should()
.BeSuccess(FetchOrder.Descending);

[Fact]
public void Build_ShouldSetPageSize() =>

[Theory]
[InlineData(1)]
[InlineData(50)]
[InlineData(100)]
public void Build_ShouldSetPageSize(int pageSize) =>
GetConversationsRequest
.Build()
.WithPageSize(50)
.WithPageSize(pageSize)
.Create()
.Map(request => request.PageSize)
.Should()
.BeSuccess(50);

.BeSuccess(pageSize);
[Fact]
public void Build_ShouldSetStartDate() =>
GetConversationsRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"page_size": 10,
"_embedded": {
"members": [
{
"id": "MEM-63f61863-4a51-4f6b-86e1-46edebio0391",
"state": "JOINED",
"_embedded": {
"user": {
"id": "USR-82e028d9-5201-4f1e-8188-604b2d3471ec",
"name": "my_user_name",
"display_name": "My User Name",
"_links": {
"self": {
"href": "https://api.nexmo.com/v1/users/USR-82e028d9-5201-4f1e-8188-604b2d3471ec"
}
}
}
},
"_links": {
"href": "https://api.nexmo.com/v1/conversations/CON-63f61863-4a51-4f6b-86e1-46edebio0391/members/MEM-63f61863-4a51-4f6b-86e1-46edebio0391"
}
}
]
},
"_links": {
"first": {
"href": "https://api.nexmo.com/v1/conversations/CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a/members?order=desc&page_size=10"
},
"self": {
"href": "https://api.nexmo.com/v1/conversations/CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a/members?order=desc&page_size=10&cursor=88b395c167da4d94e929705cbd63b82973771e7d390d274a58e301386d5762600a3ffd799bfb3fc5190c5a0d124cdd0fc72fe6e450506b18e4e2edf9fe84c7a0"
},
"next": {
"href": "https://api.nexmo.com/v1/conversations/CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a/members?order=desc&page_size=10&cursor=88b395c167da4d94e929705cbd63b829a650e69a39197bfd4c949f4243f60dc4babb696afa404d2f44e7775e32b967f2a1a0bb8fb259c0999ba5a4e501eaab55"
},
"prev": {
"href": "https://api.nexmo.com/v1/conversations/CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a/members?order=desc&page_size=10&cursor=069626a3de11d2ec900dff5042197bd75f1ce41dafc3f2b2481eb9151086e59aae9dba3e3a8858dc355232d499c310fbfbec43923ff657c0de8d49ffed9f7edb"
}
}
}
59 changes: 59 additions & 0 deletions Vonage.Test/Conversations/GetMembers/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Vonage.Conversations;
using Vonage.Conversations.GetMembers;
using Vonage.Test.Common.Extensions;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Test.Conversations.GetMembers;

[Trait("Category", "E2E")]
public class E2ETest : E2EBase
{
public E2ETest() : base(typeof(E2ETest).Namespace)
{
}

[Fact]
public async Task GetMembers()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v1/conversations/CON-123/members")
.WithParam("page_size", "50")
.WithParam("order", "desc")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.ConversationsClient
.GetMembersAsync(GetMembersRequest.Build()
.WithConversationId("CON-123")
.WithPageSize(50)
.WithOrder(FetchOrder.Descending)
.Create())
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}

[Fact]
public async Task GetMembersFromHalLink()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v1/conversations/CON-123/members")
.WithParam("page_size", "50")
.WithParam("order", "desc")
.WithParam("cursor", "7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg=")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.ConversationsClient
.GetMembersAsync(new GetMembersHalLink(new Uri(
"https://api.nexmo.com/v1/conversations/CON-123/members?order=desc&page_size=50&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D"))
.BuildRequest())
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}
}
87 changes: 87 additions & 0 deletions Vonage.Test/Conversations/GetMembers/RequestBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Vonage.Common.Monads;
using Vonage.Conversations;
using Vonage.Conversations.GetMembers;
using Vonage.Test.Common.Extensions;
using Xunit;

namespace Vonage.Test.Conversations.GetMembers;

public class RequestBuilderTest
{
private const string ConversationId = "CON-123";

[Fact]
public void Build_ShouldHaveDefaultOrder() =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.Create()
.Map(request => request.Order)
.Should()
.BeSuccess(FetchOrder.Ascending);

[Fact]
public void Build_ShouldHaveDefaultPageSize() =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.Create()
.Map(request => request.PageSize)
.Should()
.BeSuccess(10);

[Fact]
public void Build_ShouldHaveNoDefaultCursor() =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.Create()
.Map(request => request.Cursor)
.Should()
.BeSuccess(Maybe<string>.None);

[Fact]
public void Build_ShouldReturnFailure_GivenPageSizeIsHigherThanOneHundred() =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.WithPageSize(101)
.Create()
.Should()
.BeParsingFailure("PageSize cannot be higher than 100.");

[Fact]
public void Build_ShouldReturnFailure_GivenPageSizeIsLowerThanOne() =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.WithPageSize(0)
.Create()
.Should()
.BeParsingFailure("PageSize cannot be lower than 1.");

[Fact]
public void Build_ShouldSetOrder() =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.WithOrder(FetchOrder.Descending)
.Create()
.Map(request => request.Order)
.Should()
.BeSuccess(FetchOrder.Descending);

[Theory]
[InlineData(1)]
[InlineData(50)]
[InlineData(100)]
public void Build_ShouldSetPageSize(int pageSize) =>
GetMembersRequest
.Build()
.WithConversationId(ConversationId)
.WithPageSize(pageSize)
.Create()
.Map(request => request.PageSize)
.Should()
.BeSuccess(pageSize);
}
Loading

0 comments on commit ffe0c0a

Please sign in to comment.