Skip to content

Commit

Permalink
Fix Application deserialization with Meetings custom webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Oct 10, 2023
1 parent 37c429b commit 5266be5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 47 deletions.
48 changes: 1 addition & 47 deletions Vonage.Test.Unit/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,53 +268,7 @@ public async void DeleteApplicationAsync(bool passCreds)
public void GetApplication(bool passCreds)
{
var id = "78d335fa323d01149c3dd6f0d48968cf";
var expectedResponse = @"{
""id"": ""78d335fa323d01149c3dd6f0d48968cf"",
""name"": ""My Application"",
""capabilities"": {
""voice"": {
""webhooks"": {
""answer_url"": {
""address"": ""https://example.com/webhooks/answer"",
""http_method"": ""GET""
},
""fallback_answer_url"": {
""address"": ""https://fallback.example.com/webhooks/answer"",
""http_method"": ""GET""
},
""event_url"": {
""address"": ""https://example.com/webhooks/event"",
""http_method"": ""POST""
}
}
},
""messages"": {
""webhooks"": {
""inbound_url"": {
""address"": ""https://example.com/webhooks/inbound"",
""http_method"": ""POST""
},
""status_url"": {
""address"": ""https://example.com/webhooks/status"",
""http_method"": ""POST""
}
}
},
""rtc"": {
""webhooks"": {
""event_url"": {
""address"": ""https://example.com/webhooks/event"",
""http_method"": ""POST""
}
}
},
""vbc"": { }
},
""keys"": {
""public_key"": ""some public key"",
""private_key"": ""some private key""
}
}";
var expectedResponse = this.GetResponseJson();

Check notice on line 271 in Vonage.Test.Unit/ApplicationTests.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Large Method

GetApplication is no longer above the threshold for lines of code. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
var expectedUri = $"{this.ApiUrl}/v2/applications/{id}";
this.Setup(expectedUri, expectedResponse);
var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"id": "78d335fa323d01149c3dd6f0d48968cf",
"name": "My Application",
"capabilities": {
"voice": {
"webhooks": {
"answer_url": {
"address": "https://example.com/webhooks/answer",
"http_method": "GET"
},
"fallback_answer_url": {
"address": "https://fallback.example.com/webhooks/answer",
"http_method": "GET"
},
"event_url": {
"address": "https://example.com/webhooks/event",
"http_method": "POST"
}
}
},
"messages": {
"webhooks": {
"inbound_url": {
"address": "https://example.com/webhooks/inbound",
"http_method": "POST"
},
"status_url": {
"address": "https://example.com/webhooks/status",
"http_method": "POST"
}
}
},
"rtc": {
"webhooks": {
"event_url": {
"address": "https://example.com/webhooks/event",
"http_method": "POST"
}
}
},
"vbc": {},
"meetings": {
"webhooks": {
"room_changed": {
"address": "http://example.com",
"http_method": "POST"
},
"session_changed": {
"address": "http://example.com",
"http_method": "POST"
},
"recording_changed": {
"address": "https://54eba990d025.ngrok.app/recordings",
"http_method": "POST"
}
}
}
},
"keys": {
"public_key": "some public key",
"private_key": "some private key"
}
}
3 changes: 3 additions & 0 deletions Vonage.Test.Unit/Vonage.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@
<None Update="Users\UpdateUser\Data\ShouldSerializeEmpty-request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\ApplicationTests\GetApplication-response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="node ../.scripts/init.js"/>
Expand Down
9 changes: 9 additions & 0 deletions Vonage/Common/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public enum Type

[EnumMember(Value = "Unknown")]
Unknown = 6,

[EnumMember(Value = "room_changed")]
RoomChanged =7,

[EnumMember(Value = "session_changed")]
SessionChanged=8,

[EnumMember(Value = "recording_changed")]
RecordingChanged = 9,
}

}

0 comments on commit 5266be5

Please sign in to comment.