Skip to content

Commit

Permalink
refactor: clean voice tests (#414)
Browse files Browse the repository at this point in the history
* Reduce code size with set up (constructor)

* Move Json to external files, reuse Json content for sync/async variants

* Tackle duplication

* Reuse CallCommand instantiation

* Reduce duplication

* Extract Json in individual files

* Reuse StopStream Json response

* Reuse Json response

* Reuse Json responses

* Reuse Json responses

* Reuse Json responses

* Reuse Json responses

* Reuse Json responses
  • Loading branch information
Tr00d authored May 24, 2023
1 parent fa9482e commit d4d0f86
Show file tree
Hide file tree
Showing 31 changed files with 855 additions and 1,011 deletions.
6 changes: 6 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/CreateCall-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"status": "started",
"direction": "outbound",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}
31 changes: 0 additions & 31 deletions Vonage.Test.Unit/Data/VoiceTests/CreateCallAsync.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"to": [
{
"number": "14155550100",
"type": "phone"
}
],
"from": {
"number": "14155550100",
"type": "phone"
},
"ncco": [
{
"action": "talk",
"text": "Hello World"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"status": "started",
"direction": "outbound",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"to": [
{
"number": "14155550100",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"status": "started",
"direction": "outbound",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"to": [
{
"number": "14155550100",
"type": "phone"
}
],
"from": {
"number": "14155550100",
"type": "phone"
},
"ncco": [
{
"action": "talk",
"text": "Hello World"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"status": "started",
"direction": "outbound",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ncco": [
{
"action": "talk",
"text": "Hello World"
"text": "בדיקה בדיקה בדיקה"
}
],
"answer_url": [
Expand All @@ -26,6 +26,10 @@
],
"event_method": "POST",
"machine_detection": "continue",
"advanced_machine_detection": {
"behavior": "continue",
"mode": "detect"
},
"length_timer": 1,
"ringing_timer": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"status": "started",
"direction": "outbound",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22"
}
25 changes: 25 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/GetSpecificCall-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"_links": {
"self": {
"href": "/calls/63f61863-4a51-4f6b-86e1-46edebcf9356"
}
},
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22",
"to": {
"type": "phone",
"number": "447700900000"
},
"from": {
"type": "phone",
"number": "447700900001"
},
"status": "started",
"direction": "outbound",
"rate": "0.39",
"price": "23.40",
"duration": "60",
"start_time": "2020-01-01 12:00:00",
"end_time": "2020-01-01 12:00:00",
"network": "65512"
}
39 changes: 39 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/ListCalls-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"count": 100,
"page_size": 10,
"record_index": 0,
"_links": {
"self": {
"href": "/calls?page_size=10&record_index=20&order=asc"
}
},
"_embedded": {
"calls": [
{
"_links": {
"self": {
"href": "/calls/63f61863-4a51-4f6b-86e1-46edebcf9356"
}
},
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356",
"conversation_uuid": "CON-f972836a-550f-45fa-956c-12a2ab5b7d22",
"to": {
"type": "phone",
"number": "447700900000"
},
"from": {
"type": "phone",
"number": "447700900001"
},
"status": "started",
"direction": "outbound",
"rate": "0.39",
"price": "23.40",
"duration": "60",
"start_time": "2020-01-01 12:00:00",
"end_time": "2020-01-01 12:00:00",
"network": "65512"
}
]
}
}
3 changes: 3 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StartDtmf-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"digits": "1234"
}
4 changes: 4 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StartDtmf-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "DTMF sent",
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356"
}
5 changes: 5 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StartStream-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"stream_url": [
"https://example.com/waiting.mp3"
]
}
4 changes: 4 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StartStream-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "Stream started",
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stream_url": [
"https://example.com/waiting.mp3"
],
"loop": 0,
"level": "0.4"
}
3 changes: 3 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StartTalk-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"text": "Hello. How are you today?"
}
4 changes: 4 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StartTalk-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "Talk started",
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"text": "Hello. How are you today?",
"voice_name": "salli",
"loop": 0,
"level": "0.4",
"language": "en-US",
"style": 1,
"premium": true
}
4 changes: 4 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StopStream-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "Stream stopped",
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356"
}
4 changes: 4 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/StopTalk-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"message": "Talk stopped",
"uuid": "63f61863-4a51-4f6b-86e1-46edebcf9356"
}
3 changes: 3 additions & 0 deletions Vonage.Test.Unit/Data/VoiceTests/UpdateCallAsync-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"action": "earmuff"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"action": "$action",
"destination": {
"type": "ncco",
"url": [
"https://example.com/ncco.json"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"action": "transfer",
"destination": {
"type": "ncco",
"url": [
"https://example.com/ncco.json"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"action": "transfer",
"destination": {
"type": "ncco",
"ncco": [
{
"action": "talk",
"text": "Hello World"
}
]
}
}
7 changes: 7 additions & 0 deletions Vonage.Test.Unit/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Tasks;
using Moq;
using Moq.Protected;
using Vonage.Request;
using Xunit;

namespace Vonage.Test.Unit
Expand Down Expand Up @@ -38,6 +39,12 @@ public class TestBase

private static readonly string TestAssemblyName = ThisAssembly.GetName().Name;

protected Credentials BuildCredentialsForBasicAuthentication() =>
Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret);

protected Credentials BuildCredentialsForBearerAuthentication() =>
Credentials.FromAppIdAndPrivateKey(this.AppId, this.PrivateKey);

private static string AssemblyDirectory
{
get
Expand Down
Loading

0 comments on commit d4d0f86

Please sign in to comment.