Skip to content

Commit

Permalink
feat: implement RandomMessage for GetEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 11, 2024
1 parent 05fed72 commit 39d7732
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": 100,
"type": "message",
"from": "string",
"body": {
"message_type": "random"
},
"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"
}
}
}
6 changes: 6 additions & 0 deletions Vonage.Test/Conversations/GetEvent/SerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ public class SerializationTest
.Should()
.BeSuccess(BuildExpectedEvent(
new EventBodyLocationMessage(new EventBodyLocation("Longitude", "Latitude", "Name", "Address"))));

[Fact]
public void ShouldDeserializeRandomMessage() => this.helper.Serializer
.DeserializeObject<Event>(this.helper.GetResponseJson())
.Should()
.BeSuccess(BuildExpectedEvent(new EventBodyRandomMessage()));
}
3 changes: 3 additions & 0 deletions Vonage.Test/Vonage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,9 @@
<None Update="Conversations\GetEvent\Data\ShouldDeserializeLocationMessage-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Conversations\GetEvent\Data\ShouldDeserializeRandomMessage-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
4 changes: 3 additions & 1 deletion Vonage/Conversations/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public record EmbeddedEventMember(string Id);
[JsonDerivedType(typeof(EventBodyCustomMessage), "custom")]
[JsonDerivedType(typeof(EventBodyVcardMessage), "vcard")]
[JsonDerivedType(typeof(EventBodyLocationMessage), "location")]
[JsonDerivedType(typeof(EventBodyRandomMessage), "random")]
public record EventBodyBase;

public record EventBodyTextMessage(string Text) : EventBodyBase;
Expand All @@ -63,4 +64,5 @@ public record EventBodyCustomMessage(object Custom) : EventBodyBase;
public record EventBodyVcardMessage(EventBodyVcardUrl Vcard, EventBodyImageUrl Image) : EventBodyBase;
public record EventBodyVcardUrl(string Url);
public record EventBodyLocationMessage(EventBodyLocation File) : EventBodyBase;
public record EventBodyLocation(string Longitude, string Latitude, string Name, string Address);
public record EventBodyLocation(string Longitude, string Latitude, string Name, string Address);
public record EventBodyRandomMessage : EventBodyBase;

0 comments on commit 39d7732

Please sign in to comment.