-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement UpdateMember in Conversations
- Loading branch information
Showing
13 changed files
with
519 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Vonage.Test/Conversations/UpdateMember/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,52 @@ | ||
{ | ||
"id": "MEM-63f61863-4a51-4f6b-86e1-46edebio0391", | ||
"conversation_id": "CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a", | ||
"_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" | ||
} | ||
} | ||
} | ||
}, | ||
"state": "JOINED", | ||
"timestamp": { | ||
"invited": "2020-01-01T14:00:00.00Z", | ||
"joined": "2020-01-01T14:00:00.00Z", | ||
"left": "2020-01-01T14:00:00.00Z" | ||
}, | ||
"initiator": { | ||
"joined": { | ||
"is_system": true, | ||
"user_id": "USR-82e028d9-5201-4f1e-8188-604b2d3471ec", | ||
"member_id": "MEM-63f61863-4a51-4f6b-86e1-46edebio0391" | ||
} | ||
}, | ||
"channel": { | ||
"type": "app", | ||
"from": { | ||
"type": "app" | ||
}, | ||
"to": { | ||
"type": "app", | ||
"user": "string" | ||
} | ||
}, | ||
"media": { | ||
"audio_settings": { | ||
"enabled": true, | ||
"earmuffed": true, | ||
"muted": true | ||
}, | ||
"audio": true | ||
}, | ||
"knocking_id": "string", | ||
"invited_by": "MEM-63f61863-4a51-4f6b-86e1-46edebio0378", | ||
"_links": { | ||
"href": "https://api.nexmo.com/v1/conversations/CON-63f61863-4a51-4f6b-86e1-46edebio0391/members/MEM-63f61863-4a51-4f6b-86e1-46edebio0391" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Vonage.Test/Conversations/UpdateMember/Data/ShouldSerializeWithFrom-request.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,4 @@ | ||
{ | ||
"state": "joined", | ||
"from": "123456789" | ||
} |
3 changes: 3 additions & 0 deletions
3
Vonage.Test/Conversations/UpdateMember/Data/ShouldSerializeWithJoinedState-request.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,3 @@ | ||
{ | ||
"state": "joined" | ||
} |
7 changes: 7 additions & 0 deletions
7
Vonage.Test/Conversations/UpdateMember/Data/ShouldSerializeWithLeftState-request.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,7 @@ | ||
{ | ||
"state": "left", | ||
"reason": { | ||
"code": "123", | ||
"text": "Some reason." | ||
} | ||
} |
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,50 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Vonage.Common.Monads; | ||
using Vonage.Conversations.UpdateMember; | ||
using Vonage.Test.Common.Extensions; | ||
using WireMock.ResponseBuilders; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Conversations.UpdateMember; | ||
|
||
[Trait("Category", "E2E")] | ||
public class E2ETest : E2EBase | ||
{ | ||
public E2ETest() : base(typeof(E2ETest).Namespace) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public Task UpdateMemberWithJoinedState() => | ||
this.CreateConversationAsync( | ||
this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerializeWithJoinedState)), | ||
SerializationTest.BuildRequestWithJoinedState()); | ||
|
||
[Fact] | ||
public Task UpdateMemberWithLeftState() => | ||
this.CreateConversationAsync( | ||
this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerializeWithLeftState)), | ||
SerializationTest.BuildRequestWithLeftState()); | ||
|
||
[Fact] | ||
public Task UpdateMemberWithFrom() => | ||
this.CreateConversationAsync( | ||
this.Serialization.GetRequestJson(nameof(SerializationTest.ShouldSerializeWithFrom)), | ||
SerializationTest.BuildRequestWithFrom()); | ||
|
||
private async Task CreateConversationAsync(string jsonRequest, Result<UpdateMemberRequest> request) | ||
{ | ||
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create() | ||
.WithPath("/v1/conversations/CON-123/members/MEM-123") | ||
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue) | ||
.WithBody(jsonRequest) | ||
.UsingPatch()) | ||
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK) | ||
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200)))); | ||
await this.Helper.VonageClient.ConversationsClient | ||
.UpdateMemberAsync(request) | ||
.Should() | ||
.BeSuccessAsync(SerializationTest.VerifyResponse); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Vonage.Test/Conversations/UpdateMember/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,65 @@ | ||
using Vonage.Common.Monads; | ||
using Vonage.Conversations.UpdateMember; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Conversations.UpdateMember; | ||
|
||
public class RequestBuilderTest | ||
{ | ||
[Fact] | ||
public void Build_ShouldSetConversationId() => | ||
SerializationTest.BuildRequestWithJoinedState() | ||
.Map(request => request.ConversationId) | ||
.Should() | ||
.BeSuccess(SerializationTest.ValidConversationId); | ||
|
||
[Fact] | ||
public void Build_ShouldSetMemberId() => | ||
SerializationTest.BuildRequestWithJoinedState() | ||
.Map(request => request.MemberId) | ||
.Should() | ||
.BeSuccess(SerializationTest.ValidMemberId); | ||
|
||
[Fact] | ||
public void Build_ShouldSetJoinedState_GivenWithJoinedState() => | ||
SerializationTest.BuildRequestWithJoinedState() | ||
.Map(request => request.State) | ||
.Should() | ||
.BeSuccess(UpdateMemberRequest.AvailableStates.Joined); | ||
|
||
[Fact] | ||
public void Build_ShouldSetLeftState_GivenWithLeftState() => | ||
SerializationTest.BuildRequestWithLeftState() | ||
.Map(request => request.State) | ||
.Should() | ||
.BeSuccess(UpdateMemberRequest.AvailableStates.Left); | ||
|
||
[Fact] | ||
public void Build_ShouldHaveNoReason_GivenWithJoinedState() => | ||
SerializationTest.BuildRequestWithJoinedState() | ||
.Map(request => request.Reason) | ||
.Should() | ||
.BeSuccess(Maybe<Reason>.None); | ||
|
||
[Fact] | ||
public void Build_ShouldSetReason_GivenWithLeftState() => | ||
SerializationTest.BuildRequestWithLeftState() | ||
.Map(request => request.Reason) | ||
.Should() | ||
.BeSuccess(SerializationTest.ValidReason); | ||
|
||
[Fact] | ||
public void Build_ShouldSetFrom() => | ||
SerializationTest.BuildRequestWithFrom() | ||
.Map(request => request.From) | ||
.Should() | ||
.BeSuccess(SerializationTest.ValidFrom); | ||
|
||
[Fact] | ||
public void Build_ShouldHaveNoFrom_GivenDefault() => | ||
SerializationTest.BuildRequestWithJoinedState() | ||
.Map(request => request.From) | ||
.Should() | ||
.BeSuccess(Maybe<string>.None); | ||
} |
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,20 @@ | ||
using Vonage.Conversations.UpdateMember; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Conversations.UpdateMember; | ||
|
||
[Trait("Category", "Request")] | ||
public class RequestTest | ||
{ | ||
[Fact] | ||
public void GetEndpointPath_ShouldReturnApiEndpoint() => | ||
UpdateMemberRequest.Build() | ||
.WithConversationId("CON-123") | ||
.WithMemberId("MEM-123") | ||
.WithJoinedState() | ||
.Create() | ||
.Map(request => request.GetEndpointPath()) | ||
.Should() | ||
.BeSuccess("/v1/conversations/CON-123/members/MEM-123"); | ||
} |
118 changes: 118 additions & 0 deletions
118
Vonage.Test/Conversations/UpdateMember/SerializationTest.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,118 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Vonage.Common; | ||
using Vonage.Common.Monads; | ||
using Vonage.Conversations; | ||
using Vonage.Conversations.UpdateMember; | ||
using Vonage.Serialization; | ||
using Vonage.Test.Common; | ||
using Vonage.Test.Common.Extensions; | ||
using Xunit; | ||
|
||
namespace Vonage.Test.Conversations.UpdateMember; | ||
|
||
[Trait("Category", "Serialization")] | ||
public class SerializationTest | ||
{ | ||
internal const string ValidConversationId = "CON-123"; | ||
internal const string ValidMemberId = "MEM-123"; | ||
internal const string ValidFrom = "123456789"; | ||
|
||
private readonly SerializationTestHelper helper = new SerializationTestHelper( | ||
typeof(SerializationTest).Namespace, | ||
JsonSerializerBuilder.BuildWithSnakeCase()); | ||
|
||
internal static Reason ValidReason => new Reason("123", "Some reason."); | ||
|
||
[Fact] | ||
public void ShouldSerializeWithJoinedState() => | ||
BuildRequestWithJoinedState() | ||
.GetStringContent() | ||
.Should() | ||
.BeSuccess(this.helper.GetRequestJson()); | ||
|
||
internal static Result<UpdateMemberRequest> BuildRequestWithJoinedState() => | ||
UpdateMemberRequest.Build() | ||
.WithConversationId(ValidConversationId) | ||
.WithMemberId(ValidMemberId) | ||
.WithJoinedState() | ||
.Create(); | ||
|
||
[Fact] | ||
public void ShouldSerializeWithLeftState() => | ||
BuildRequestWithLeftState() | ||
.GetStringContent() | ||
.Should() | ||
.BeSuccess(this.helper.GetRequestJson()); | ||
|
||
internal static Result<UpdateMemberRequest> BuildRequestWithLeftState() => | ||
UpdateMemberRequest.Build() | ||
.WithConversationId(ValidConversationId) | ||
.WithMemberId(ValidMemberId) | ||
.WithLeftState(ValidReason) | ||
.Create(); | ||
|
||
[Fact] | ||
public void ShouldSerializeWithFrom() => | ||
BuildRequestWithFrom() | ||
.GetStringContent() | ||
.Should() | ||
.BeSuccess(this.helper.GetRequestJson()); | ||
|
||
internal static Result<UpdateMemberRequest> BuildRequestWithFrom() => | ||
UpdateMemberRequest.Build() | ||
.WithConversationId(ValidConversationId) | ||
.WithMemberId(ValidMemberId) | ||
.WithJoinedState() | ||
.WithFrom(ValidFrom) | ||
.Create(); | ||
|
||
[Fact] | ||
public void ShouldDeserialize200() => this.helper.Serializer | ||
.DeserializeObject<Member>(this.helper.GetResponseJson()) | ||
.Should() | ||
.BeSuccess(VerifyResponse); | ||
|
||
internal static void VerifyResponse(Member response) | ||
{ | ||
response.Id.Should().Be("MEM-63f61863-4a51-4f6b-86e1-46edebio0391"); | ||
response.ConversationId.Should().Be("CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a"); | ||
response.State.Should().Be("JOINED"); | ||
response.KnockingId.Should().Be("string"); | ||
response.InvitedBy.Should().Be("MEM-63f61863-4a51-4f6b-86e1-46edebio0378"); | ||
response.Timestamp.Should().Be(new MemberTimestamp( | ||
DateTimeOffset.Parse("2020-01-01T14:00:00.00Z"), | ||
DateTimeOffset.Parse("2020-01-01T14:00:00.00Z"), | ||
DateTimeOffset.Parse("2020-01-01T14:00:00.00Z") | ||
)); | ||
response.Media.Should().Be(new MemberMedia( | ||
new MemberMediaSettings(true, true, true), | ||
true | ||
)); | ||
response.Links.Should() | ||
.Be(new HalLink(new Uri( | ||
"https://api.nexmo.com/v1/conversations/CON-63f61863-4a51-4f6b-86e1-46edebio0391/members/MEM-63f61863-4a51-4f6b-86e1-46edebio0391"))); | ||
response.Embedded.Should().Be(new MemberEmbedded( | ||
new MemberEmbeddedUser( | ||
"USR-82e028d9-5201-4f1e-8188-604b2d3471ec", | ||
"my_user_name", | ||
"My User Name", | ||
new HalLinks<HalLink> | ||
{ | ||
Self = new HalLink( | ||
new Uri("https://api.nexmo.com/v1/users/USR-82e028d9-5201-4f1e-8188-604b2d3471ec")), | ||
} | ||
) | ||
)); | ||
response.Initiator.Should().Be(new MemberInitiator( | ||
new MemberInitiatorJoined(true, "USR-82e028d9-5201-4f1e-8188-604b2d3471ec", | ||
"MEM-63f61863-4a51-4f6b-86e1-46edebio0391"), | ||
null | ||
)); | ||
response.Channel.Should().Be(new MemberChannel( | ||
ChannelType.App, | ||
MemberChannelFrom.FromChannels(ChannelType.App), | ||
new MemberChannelToV(ChannelType.App, "string", null, null) | ||
)); | ||
} | ||
} |
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
Oops, something went wrong.