From 9c6318423d993d5c8879816cf1571a99391c2134 Mon Sep 17 00:00:00 2001
From: Jean-Pierre Portier <jean-pierre.portier@mailgun.com>
Date: Tue, 15 Oct 2024 13:31:50 +0200
Subject: [PATCH] test (Voice/E2E): Extends 2E2 tests for ICE

---
 .../domains/voice/v0/WebhooksEventsSteps.java | 34 +++++++++++++++++++
 .../domains/voice/v1/WebhooksEventsSteps.java | 30 ++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v0/WebhooksEventsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v0/WebhooksEventsSteps.java
index 1b24720f..0aeb6a8f 100644
--- a/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v0/WebhooksEventsSteps.java
+++ b/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v0/WebhooksEventsSteps.java
@@ -5,9 +5,12 @@
 import com.sinch.sdk.domains.voice.models.CallReasonType;
 import com.sinch.sdk.domains.voice.models.CallResultType;
 import com.sinch.sdk.domains.voice.models.DestinationNumber;
+import com.sinch.sdk.domains.voice.models.DestinationNumberType;
+import com.sinch.sdk.domains.voice.models.DomainType;
 import com.sinch.sdk.domains.voice.models.Price;
 import com.sinch.sdk.domains.voice.models.webhooks.AnsweredCallEvent;
 import com.sinch.sdk.domains.voice.models.webhooks.DisconnectCallEvent;
+import com.sinch.sdk.domains.voice.models.webhooks.IncomingCallEvent;
 import com.sinch.sdk.domains.voice.models.webhooks.MenuInputType;
 import com.sinch.sdk.domains.voice.models.webhooks.MenuResult;
 import com.sinch.sdk.domains.voice.models.webhooks.MenuResultInputMethodType;
@@ -15,6 +18,7 @@
 import com.sinch.sdk.domains.voice.models.webhooks.WebhooksEvent;
 import com.sinch.sdk.e2e.Config;
 import com.sinch.sdk.e2e.domains.WebhooksHelper;
+import com.sinch.sdk.models.E164PhoneNumber;
 import io.cucumber.java.en.Given;
 import io.cucumber.java.en.Then;
 import io.cucumber.java.en.When;
@@ -34,6 +38,7 @@ public class WebhooksEventsSteps {
   WebhooksHelper.Response<WebhooksEvent> pieSequence;
   WebhooksHelper.Response<WebhooksEvent> diceEvent;
   WebhooksHelper.Response<WebhooksEvent> aceEvent;
+  WebhooksHelper.Response<WebhooksEvent> iceEvent;
 
   PromptInputEvent expectedPieReturnEvent =
       PromptInputEvent.builder()
@@ -90,6 +95,24 @@ public class WebhooksEventsSteps {
           .setCustom("Custom text")
           .build();
 
+  IncomingCallEvent expectedIceEvent =
+      IncomingCallEvent.builder()
+          .setCallId("1ce0ffee-ca11-ca11-ca11-abcdef000053")
+          .setCallResourceUrl(
+              "https://calling-use1.api.sinch.com/calling/v1/calls/id/1ce0ffee-ca11-ca11-ca11-abcdef000053")
+          .setTimestamp(Instant.parse("2024-06-06T17:20:14Z"))
+          .setVersion(1)
+          .setUserRate(Price.builder().setCurrencyId("USD").setAmount(0.0F).build())
+          .setCli("12015555555")
+          .setTo(
+              new DestinationNumber(
+                  E164PhoneNumber.valueOf("+12017777777"), DestinationNumberType.DID))
+          .setDomain(DomainType.PSTN)
+          .setApplicationKey("f00dcafe-abba-c0de-1dea-dabb1ed4caf3")
+          .setOriginationType(DomainType.PSTN)
+          .setRdnis("")
+          .build();
+
   @Given("^the Voice Webhooks handler is available$")
   public void serviceAvailable() {
     service = Config.getSinchClient().voice().webhooks();
@@ -121,6 +144,12 @@ public void sendACEEvent() throws IOException {
         WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/ace"), service::unserializeWebhooksEvent);
   }
 
+  @When("^I send a request to trigger a \"ICE\" event$")
+  public void sendICEEvent() throws IOException {
+    iceEvent =
+        WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/ice"), service::unserializeWebhooksEvent);
+  }
+
   @Then("the header of the {string} event with a {string} type contains a valid authorization")
   public void validatePieHeader(String event, String type) {
 
@@ -146,6 +175,8 @@ public void validateHeader(String event) {
       receivedEvent = diceEvent;
     } else if (event.equals("ACE")) {
       receivedEvent = aceEvent;
+    } else if (event.equals("ICE")) {
+      receivedEvent = iceEvent;
     } else {
       Assertions.fail();
     }
@@ -184,6 +215,9 @@ public void validateEvent(String event) {
     } else if (event.equals("ACE")) {
       receivedEvent = aceEvent;
       expectedEvent = expectedAceEvent;
+    } else if (event.equals("ICE")) {
+      receivedEvent = iceEvent;
+      expectedEvent = expectedIceEvent;
     } else {
       Assertions.fail();
     }
diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/WebhooksEventsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/WebhooksEventsSteps.java
index 27c4ab55..369bea8c 100644
--- a/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/WebhooksEventsSteps.java
+++ b/client/src/test/java/com/sinch/sdk/e2e/domains/voice/v1/WebhooksEventsSteps.java
@@ -2,12 +2,15 @@
 
 import com.sinch.sdk.core.TestHelpers;
 import com.sinch.sdk.domains.voice.api.v1.WebHooksService;
+import com.sinch.sdk.domains.voice.models.v1.Domain;
 import com.sinch.sdk.domains.voice.models.v1.Price;
 import com.sinch.sdk.domains.voice.models.v1.calls.response.CallResult;
+import com.sinch.sdk.domains.voice.models.v1.destination.DestinationDid;
 import com.sinch.sdk.domains.voice.models.v1.destination.DestinationPstn;
 import com.sinch.sdk.domains.voice.models.v1.webhooks.AnsweredCallEvent;
 import com.sinch.sdk.domains.voice.models.v1.webhooks.DisconnectedCallEvent;
 import com.sinch.sdk.domains.voice.models.v1.webhooks.DisconnectedCallEvent.ReasonEnum;
+import com.sinch.sdk.domains.voice.models.v1.webhooks.IncomingCallEvent;
 import com.sinch.sdk.domains.voice.models.v1.webhooks.MenuResult;
 import com.sinch.sdk.domains.voice.models.v1.webhooks.MenuResult.InputMethodEnum;
 import com.sinch.sdk.domains.voice.models.v1.webhooks.MenuResult.TypeEnum;
@@ -34,6 +37,7 @@ public class WebhooksEventsSteps {
   WebhooksHelper.Response<VoiceWebhookEvent> pieSequence;
   WebhooksHelper.Response<VoiceWebhookEvent> diceEvent;
   WebhooksHelper.Response<VoiceWebhookEvent> aceEvent;
+  WebhooksHelper.Response<VoiceWebhookEvent> iceEvent;
 
   PromptInputEvent expectedPieReturnEvent =
       PromptInputEvent.builder()
@@ -91,6 +95,22 @@ public class WebhooksEventsSteps {
           .setApplicationKey("f00dcafe-abba-c0de-1dea-dabb1ed4caf3")
           .build();
 
+  IncomingCallEvent expectedIceEvent =
+      IncomingCallEvent.builder()
+          .setCallid("1ce0ffee-ca11-ca11-ca11-abcdef000053")
+          .setCallResourceUrl(
+              "https://calling-use1.api.sinch.com/calling/v1/calls/id/1ce0ffee-ca11-ca11-ca11-abcdef000053")
+          .setTimestamp(Instant.parse("2024-06-06T17:20:14Z"))
+          .setVersion(1)
+          .setUserRate(Price.builder().setCurrencyId("USD").setAmount(0.0F).build())
+          .setCli("12015555555")
+          .setTo(DestinationDid.from("+12017777777"))
+          .setDomain(Domain.PSTN)
+          .setApplicationKey("f00dcafe-abba-c0de-1dea-dabb1ed4caf3")
+          .setOriginationType(Domain.PSTN2)
+          .setRdnis("")
+          .build();
+
   @Given("^the Voice Webhooks handler is available$")
   public void serviceAvailable() {
     service = Config.getSinchClient().voice().v1().webhooks();
@@ -117,6 +137,11 @@ public void sendACEEvent() throws IOException {
     aceEvent = WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/ace"), service::parseEvent);
   }
 
+  @When("^I send a request to trigger a \"ICE\" event$")
+  public void sendICEEvent() throws IOException {
+    iceEvent = WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/ice"), service::parseEvent);
+  }
+
   @Then("the header of the {string} event with a {string} type contains a valid authorization")
   public void validatePieHeader(String event, String type) {
 
@@ -142,6 +167,8 @@ public void validateHeader(String event) {
       receivedEvent = diceEvent;
     } else if (event.equals("ACE")) {
       receivedEvent = aceEvent;
+    } else if (event.equals("ICE")) {
+      receivedEvent = iceEvent;
     } else {
       Assertions.fail();
     }
@@ -180,6 +207,9 @@ public void validateEvent(String event) {
     } else if (event.equals("ACE")) {
       receivedEvent = aceEvent;
       expectedEvent = expectedAceEvent;
+    } else if (event.equals("ICE")) {
+      receivedEvent = iceEvent;
+      expectedEvent = expectedIceEvent;
     } else {
       Assertions.fail();
     }