Skip to content

Commit

Permalink
feat: implement GetEvents in Conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 12, 2024
1 parent d969926 commit b43cf1f
Show file tree
Hide file tree
Showing 18 changed files with 799 additions and 40 deletions.
8 changes: 4 additions & 4 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 GetMembersHalLink(new Uri(
.GetConversationsAsync(new GetConversationsHalLink(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 GetMembersHalLinkTest
public class GetEventsHalLinkTest
{
[Fact]
public void BuildRequestForPrevious_ShouldReturnSuccess() =>
new GetMembersHalLink(new Uri("https://api.nexmo.com/v1/users?order=desc&page_size=10"))
new GetConversationsHalLink(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 class GetMembersHalLinkTest
PageSize = 10,
Order = FetchOrder.Descending,
});

[Fact]
public void BuildRequestForPrevious_ShouldReturnSuccess_WithCursor() =>
new GetMembersHalLink(new Uri(
new GetConversationsHalLink(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 GetMembersHalLink(new Uri(
new GetConversationsHalLink(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 GetMembersHalLink(new Uri(
new GetConversationsHalLink(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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"page_size": 10,
"_links": {
"first": {
"href": "https://api.nexmo.com/v1/conversations/CON-123/events?page_size=10&order=asc&exclude_deleted_events=false"
},
"self": {
"href": "https://api.nexmo.com/v1/conversations/CON-123/events?page_size=10&order=asc&exclude_deleted_events=false"
},
"next": {
"href": "https://api.nexmo.com/v1/conversations/CON-123/events?page_size=10&order=asc&exclude_deleted_events=false"
},
"prev": {
"href": "https://api.nexmo.com/v1/conversations/CON-123/events?page_size=10&order=asc&exclude_deleted_events=false"
}
},
"_embedded": [
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "text",
"text": "string"
},
"timestamp": "2020-01-01T14:00:00.00Z",
"_embedded": {
"from_user": {
"id": "USR-82e028d9-5201-4f1e-8188-604b2d3471ec",
"name": "my_user_name",
"display_name": "My User Name",
"image_url": "https://example.com/image.png",
"custom_data": {
"field_1": "value_1",
"field_2": "value_2"
}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v1/conversations/CON-123/events/100"
}
}
}
]
}
91 changes: 91 additions & 0 deletions Vonage.Test/Conversations/GetEvents/E2ETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Vonage.Conversations;
using Vonage.Conversations.GetEvents;
using Vonage.Test.Common.Extensions;
using WireMock.ResponseBuilders;
using Xunit;

namespace Vonage.Test.Conversations.GetEvents;

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

[Fact]
public async Task GetEventsWithDefaultRequest()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v1/conversations/CON-123/events")
.WithParam("page_size", "10")
.WithParam("order", "asc")
.WithParam("exclude_deleted_events", "false")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.ConversationsClient
.GetEventsAsync(GetEventsRequest.Build()
.WithConversationId("CON-123")
.Create())
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}

[Fact]
public async Task GetEvents()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v1/conversations/CON-123/events")
.WithParam("page_size", "50")
.WithParam("order", "desc")
.WithParam("exclude_deleted_events", "true")
.WithParam("event_type", "submitted")
.WithParam("start_id", "123")
.WithParam("end_id", "456")
.WithHeader("Authorization", this.Helper.ExpectedAuthorizationHeaderValue)
.UsingGet())
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.OK)
.WithBody(this.Serialization.GetResponseJson(nameof(SerializationTest.ShouldDeserialize200))));
await this.Helper.VonageClient.ConversationsClient
.GetEventsAsync(GetEventsRequest.Build()
.WithConversationId("CON-123")
.WithPageSize(50)
.WithOrder(FetchOrder.Descending)
.WithEventType("submitted")
.WithStartId("123")
.WithEndId("456")
.ExcludeDeletedEvents()
.Create())
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}

[Fact]
public async Task GetEventsFromHalLink()
{
this.Helper.Server.Given(WireMock.RequestBuilders.Request.Create()
.WithPath("/v1/conversations/CON-123/events")
.WithParam("page_size", "50")
.WithParam("order", "desc")
.WithParam("exclude_deleted_events", "true")
.WithParam("event_type", "submitted")
.WithParam("start_id", "123")
.WithParam("end_id", "456")
.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
.GetEventsAsync(new GetEventsHalLink(new Uri(
"https://api.nexmo.com/v1/conversations/CON-123/events?page_size=50&order=desc&exclude_deleted_events=true&cursor=7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg%3D&start_id=123&end_id=456&event_type=submitted"))
.BuildRequest())
.Should()
.BeSuccessAsync(SerializationTest.VerifyExpectedResponse);
}
}
Loading

0 comments on commit b43cf1f

Please sign in to comment.