From e05b426907aec257b349864035b606000e3cc728 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 22 Jul 2022 12:43:06 +0100
Subject: [PATCH] Add ConnectionGetPartner functor

---
 Sources/ElixxirDAppsSDK/Connection.swift      | 10 +++--
 .../ConnectionGetPartner.swift                | 36 ++++++++++++++++
 .../Legacy/ConnectionPartnerProvider.swift    | 41 -------------------
 3 files changed, 43 insertions(+), 44 deletions(-)
 create mode 100644 Sources/ElixxirDAppsSDK/ConnectionGetPartner.swift
 delete mode 100644 Sources/ElixxirDAppsSDK/Legacy/ConnectionPartnerProvider.swift

diff --git a/Sources/ElixxirDAppsSDK/Connection.swift b/Sources/ElixxirDAppsSDK/Connection.swift
index c2e269ee..1d857798 100644
--- a/Sources/ElixxirDAppsSDK/Connection.swift
+++ b/Sources/ElixxirDAppsSDK/Connection.swift
@@ -2,24 +2,28 @@ import Bindings
 
 public struct Connection {
   public var getId: ConnectionGetId
+  public var getPartner: ConnectionGetPartner
 }
 
 extension Connection {
   public static func live(_ bindingsConnection: BindingsConnection) -> Connection {
     Connection(
-      getId: .live(bindingsConnection)
+      getId: .live(bindingsConnection),
+      getPartner: .live(bindingsConnection)
     )
   }
 
   public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> Connection {
     Connection(
-      getId: .live(bindingsConnection)
+      getId: .live(bindingsConnection),
+      getPartner: .live(bindingsConnection)
     )
   }
 }
 
 extension Connection {
   public static let unimplemented = Connection(
-    getId: .unimplemented
+    getId: .unimplemented,
+    getPartner: .unimplemented
   )
 }
diff --git a/Sources/ElixxirDAppsSDK/ConnectionGetPartner.swift b/Sources/ElixxirDAppsSDK/ConnectionGetPartner.swift
new file mode 100644
index 00000000..50f78421
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/ConnectionGetPartner.swift
@@ -0,0 +1,36 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct ConnectionGetPartner {
+  public var run: () -> Data
+
+  public func callAsFunction() -> Data {
+    run()
+  }
+}
+
+extension ConnectionGetPartner {
+  public static func live(_ bindingsConnection: BindingsConnection) -> ConnectionGetPartner {
+    ConnectionGetPartner {
+      guard let data = bindingsConnection.getPartner() else {
+        fatalError("BindingsConnection.getPartner returned `nil`")
+      }
+      return data
+    }
+  }
+
+  public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> ConnectionGetPartner {
+    ConnectionGetPartner {
+      guard let data = bindingsConnection.getPartner() else {
+        fatalError("BindingsAuthenticatedConnection.getPartner returned `nil`")
+      }
+      return data
+    }
+  }
+}
+
+extension ConnectionGetPartner {
+  public static let unimplemented = ConnectionGetPartner(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
diff --git a/Sources/ElixxirDAppsSDK/Legacy/ConnectionPartnerProvider.swift b/Sources/ElixxirDAppsSDK/Legacy/ConnectionPartnerProvider.swift
deleted file mode 100644
index 8d2bcbce..00000000
--- a/Sources/ElixxirDAppsSDK/Legacy/ConnectionPartnerProvider.swift
+++ /dev/null
@@ -1,41 +0,0 @@
-import Bindings
-
-public struct ConnectionPartnerProvider {
-  public var get: () -> Data
-
-  public func callAsFunction() -> Data {
-    get()
-  }
-}
-
-extension ConnectionPartnerProvider {
-  public static func live(
-    bindingsConnection: BindingsConnection
-  ) -> ConnectionPartnerProvider {
-    ConnectionPartnerProvider {
-      guard let data = bindingsConnection.getPartner() else {
-        fatalError("BindingsConnection.getPartner returned `nil`")
-      }
-      return data
-    }
-  }
-
-  public static func live(
-    bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
-  ) -> ConnectionPartnerProvider {
-    ConnectionPartnerProvider {
-      guard let data = bindingsAuthenticatedConnection.getPartner() else {
-        fatalError("BindingsAuthenticatedConnection.getPartner returned `nil`")
-      }
-      return data
-    }
-  }
-}
-
-#if DEBUG
-extension ConnectionPartnerProvider {
-  public static let failing = ConnectionPartnerProvider {
-    fatalError("Not implemented")
-  }
-}
-#endif
-- 
GitLab