Skip to content

Commit

Permalink
feat: implement GetEvents responses serialization in Conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 11, 2024
1 parent 13e1477 commit 05fed72
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal static void VerifyExpectedResponse(GetConversationsResponse response)
Maybe<Properties>.None,
new Links(new HalLink(new Uri(
"https://api.nexmo.com/v1/conversations/CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a"))),
Maybe<EmbeddedData>.None),
Maybe<EmbeddedConversationData>.None),
});
response.Links.First.Href.Should()
.Be(new Uri("https://api.nexmo.com/v1/conversations?order=desc&page_size=10"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "audio",
"audio": {
"url": "https://example.com/audio.mp3"
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "custom",
"custom": {}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "file",
"file": {
"url": "https://example.com/file.txt"
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "image",
"image": {
"url": "https://example.com/image.png"
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "location",
"location": {
"longitude": "Longitude",
"latitude": "Latitude",
"name": "Name",
"address": "Address"
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "template",
"template": {
"name": "Template",
"parameters": [],
"whatsapp": {
"policy": "deterministic",
"locale": "en-US"
}
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "vcard",
"vcard": {
"url": "https://example.com/file.txt"
},
"image": {
"url": "https://example.com/image.png"
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "video",
"video": {
"url": "https://example.com/video.mkv"
}
},
"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": {}
},
"from_member": {
"id": "string"
}
},
"_links": {
"self": {
"href": "https://api.nexmo.com/v0.1/conversations/CON-1234/events/100"
}
}
}
48 changes: 48 additions & 0 deletions Vonage.Test/Conversations/GetEvent/RequestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Vonage.Conversations.GetEvent;
using Vonage.Test.Common.Extensions;
using Xunit;

namespace Vonage.Test.Conversations.GetEvent;

[Trait("Category", "Request")]
public class RequestTest
{
[Fact]
public void GetEndpointPath_ShouldReturnApiEndpoint() =>
GetEventRequest.Parse("CON-123", "EVE-123")
.Map(request => request.GetEndpointPath())
.Should()
.BeSuccess("/v1/conversations/CON-123/events/EVE-123");

[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void Parse_ShouldReturnFailure_GivenConversationIdIsEmpty(string invalidId) =>
GetEventRequest.Parse(invalidId, "MEM-123")
.Should()
.BeParsingFailure("ConversationId cannot be null or whitespace.");

[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void Parse_ShouldReturnFailure_GivenEventIdIsEmpty(string invalidId) =>
GetEventRequest.Parse("CON-123", invalidId)
.Should()
.BeParsingFailure("EventId cannot be null or whitespace.");

[Fact]
public void Parse_ShouldSetConversationId() =>
GetEventRequest.Parse("CON-123", "EVE-123")
.Map(request => request.ConversationId)
.Should()
.BeSuccess("CON-123");

[Fact]
public void Parse_ShouldSetMemberId() =>
GetEventRequest.Parse("CON-123", "EVE-123")
.Map(request => request.EventId)
.Should()
.BeSuccess("EVE-123");
}
Loading

0 comments on commit 05fed72

Please sign in to comment.