Skip to content

Commit

Permalink
fix: make StartTime and EndTime nullable on Completed webhook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed May 10, 2024
1 parent 80a39b1 commit e8a9b82
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
76 changes: 61 additions & 15 deletions Vonage.Test/WebhookStructsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void TestAnswer()
Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", answerWebhook.Uuid);
Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", answerWebhook.ConversationUuid);
}

[Fact]
public void TestAnswered()
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public void TestAnswered()
Assert.Equal("1234", answeredWebhook.Network);
Assert.Equal("0.02", answeredWebhook.Rate);
}

[Fact]
public void TestCallbackStatusEventWithUnenumeratedDetail()
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public void TestCallbackStatusEventWithUnenumeratedDetail()
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), callStatusWebhook.TimeStamp);
}

[Theory]
[InlineData("disconnected")]
[InlineData("cancelled")]
Expand Down Expand Up @@ -125,7 +125,7 @@ public void TestCallStatusEvent(string type)
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), callStatusWebhook.TimeStamp);
}

[Fact]
public void TestCallStatusEventWithDetail()
{
Expand All @@ -152,7 +152,7 @@ public void TestCallStatusEventWithDetail()
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), callStatusWebhook.TimeStamp);
}

[Fact]
public void TestCompleted()
{
Expand Down Expand Up @@ -193,7 +193,53 @@ public void TestCompleted()
Assert.Equal("0.03", completedWebhook.Price);
Assert.Equal("2", completedWebhook.Duration);
}


[Fact]
public void TestCompleted_WithNullStartTime()
{
var json = @"
{
""from"":""442079460000"",
""to"":""447700900000"",
""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""status"":""completed"",
""direction"":""outbound"",
""timestamp"":""2020-01-01T12:00:00.000Z"",
""start_time"":null,
""end_time"":""2020-01-01T12:00:01.000Z"",
""rate"":""0.02"",
""price"":""0.03"",
""network"":""1234"",
""duration"":""2""
}";
var completedWebhook = (Completed) EventBase.ParseEvent(json);
completedWebhook.StartTime.Should().BeNull();
}

[Fact]
public void TestCompleted_WithNullEndTime()
{
var json = @"
{
""from"":""442079460000"",
""to"":""447700900000"",
""uuid"":""aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""conversation_uuid"":""CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab"",
""status"":""completed"",
""direction"":""outbound"",
""timestamp"":""2020-01-01T12:00:00.000Z"",
""start_time"":""2020-01-01T12:00:00.000Z"",
""end_time"":null,
""rate"":""0.02"",
""price"":""0.03"",
""network"":""1234"",
""duration"":""2""
}";
var completedWebhook = (Completed) EventBase.ParseEvent(json);
completedWebhook.EndTime.Should().BeNull();
}

[Fact]
public void TestDtmfMultiInputStruct()
{
Expand All @@ -218,13 +264,13 @@ public void TestDtmfMultiInputStruct()
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), inputWebhook.TimeStamp);
}

[Fact]
public void TestEmpty()
{
Assert.Null(EventBase.ParseEvent("{}"));
}

[Fact]
public void TestError()
{
Expand All @@ -241,7 +287,7 @@ public void TestError()
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), errorWebhook.TimeStamp);
}

[Theory]
[InlineData("human")]
[InlineData("machine")]
Expand All @@ -268,7 +314,7 @@ public void TestHumanMachine(string type)
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), humanMachineWebhook.TimeStamp);
}

[Fact]
public void TestNotifications()
{
Expand All @@ -285,7 +331,7 @@ public void TestNotifications()
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), notification.TimeStamp);
}

[Fact]
public void TestRecord()
{
Expand Down Expand Up @@ -315,7 +361,7 @@ public void TestRecord()
Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", recordWebhook.Uuid);
Assert.Equal("CON-aaaaaaaa-bbbb-cccc-dddd-0123456789ab", recordWebhook.ConversationUuid);
}

[Fact]
public void TestSpeechMultiInputStruct()
{
Expand All @@ -342,7 +388,7 @@ public void TestSpeechMultiInputStruct()
CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal |
DateTimeStyles.AdjustToUniversal), inputWebhook.TimeStamp);
}

[Fact]
public void TestTransfer()
{
Expand All @@ -361,7 +407,7 @@ public void TestTransfer()
DateTimeStyles.AdjustToUniversal), transferWebhook.TimeStamp);
Assert.Equal("aaaaaaaa-bbbb-cccc-dddd-0123456789ab", transferWebhook.Uuid);
}

[Fact]
public void ShouldDeserializedAnswered_GivenStartTimeIsNull()
{
Expand All @@ -370,7 +416,7 @@ public void ShouldDeserializedAnswered_GivenStartTimeIsNull()
File.ReadAllText("Data/Webhooks/ShouldDeserializedAnswered_GivenStartTimeIsNull.json"));
deserializedEvent.StartTime.Should().BeNull();
}

public class Foo
{
public string bar { get; set; }
Expand Down
14 changes: 7 additions & 7 deletions Vonage/Voice/EventWebhooks/Completed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ public class Completed : CallStatusEvent
/// </summary>
[JsonProperty("duration")]
public string Duration { get; set; }

/// <summary>
/// Timestamp (ISO 8601 format) of the end time of the call
/// </summary>
[JsonProperty("end_time")]
public DateTime EndTime { get; set; }

public DateTime? EndTime { get; set; }
/// <summary>
/// The type of network that was used in the call
/// </summary>
[JsonProperty("network")]
public string Network { get; set; }

/// <summary>
/// Total cost of the call (EUR)
/// </summary>
[JsonProperty("price")]
public string Price { get; set; }

/// <summary>
/// Cost per minute of the call (EUR)
/// </summary>
[JsonProperty("rate")]
public string Rate { get; set; }

/// <summary>
/// Timestamp (ISO 8601 format)
/// </summary>
[JsonProperty("start_time")]
public DateTime StartTime { get; set; }
public DateTime? StartTime { get; set; }
}

0 comments on commit e8a9b82

Please sign in to comment.