-
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 GetMembers in Conversations
- Loading branch information
Showing
16 changed files
with
557 additions
and
40 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
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
40 changes: 40 additions & 0 deletions
40
Vonage.Test/Conversations/GetMembers/Data/ShouldDeserialize200-response.json
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,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" | ||
} | ||
} | ||
} |
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,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
87
Vonage.Test/Conversations/GetMembers/RequestBuilderTest.cs
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,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); | ||
} |
Oops, something went wrong.