From b15f1caa88b2f6894983c0d901cbbda315a0345a Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 26 Aug 2022 12:52:28 +0100
Subject: [PATCH] Replace MakeContact with Contact static extensions

---
 .../XXClient/Callbacks/UdSearchCallback.swift | 18 +++---------
 Sources/XXClient/Helpers/MakeContact.swift    | 26 -----------------
 Sources/XXClient/Models/Contact.swift         | 28 +++++++++++++++++++
 3 files changed, 32 insertions(+), 40 deletions(-)
 delete mode 100644 Sources/XXClient/Helpers/MakeContact.swift

diff --git a/Sources/XXClient/Callbacks/UdSearchCallback.swift b/Sources/XXClient/Callbacks/UdSearchCallback.swift
index 4799032b..88f17393 100644
--- a/Sources/XXClient/Callbacks/UdSearchCallback.swift
+++ b/Sources/XXClient/Callbacks/UdSearchCallback.swift
@@ -16,20 +16,13 @@ extension UdSearchCallback {
 }
 
 extension UdSearchCallback {
-  func makeBindingsUdSearchCallback(
-    makeContact: MakeContact = .live()
-  ) -> BindingsUdSearchCallbackProtocol {
+  func makeBindingsUdSearchCallback() -> BindingsUdSearchCallbackProtocol {
     class CallbackObject: NSObject, BindingsUdSearchCallbackProtocol {
-      init(
-        callback: UdSearchCallback,
-        makeContact: MakeContact
-      ) {
+      init(_ callback: UdSearchCallback) {
         self.callback = callback
-        self.makeContact = makeContact
       }
 
       let callback: UdSearchCallback
-      let makeContact: MakeContact
 
       func callback(_ contactListJSON: Data?, err: Error?) {
         if let error = err {
@@ -37,7 +30,7 @@ extension UdSearchCallback {
         } else if let data = contactListJSON {
           do {
             let contactsData = try JSONDecoder().decode([Data].self, from: data)
-            let contacts: [Contact] = contactsData.map { makeContact($0) }
+            let contacts: [Contact] = contactsData.map { Contact.live($0) }
             callback.handle(.success(contacts))
           } catch {
             callback.handle(.failure(error as NSError))
@@ -48,9 +41,6 @@ extension UdSearchCallback {
       }
     }
 
-    return CallbackObject(
-      callback: self,
-      makeContact: makeContact
-    )
+    return CallbackObject(self)
   }
 }
diff --git a/Sources/XXClient/Helpers/MakeContact.swift b/Sources/XXClient/Helpers/MakeContact.swift
deleted file mode 100644
index 2e0027bd..00000000
--- a/Sources/XXClient/Helpers/MakeContact.swift
+++ /dev/null
@@ -1,26 +0,0 @@
-import Foundation
-
-public struct MakeContact {
-  public var run: (Data) -> Contact
-
-  public func callAsFunction(_ data: Data) -> Contact {
-    run(data)
-  }
-}
-
-extension MakeContact {
-  public static func live(
-    getIdFromContact: GetIdFromContact = .live,
-    getPublicKeyFromContact: GetPublicKeyFromContact = .live,
-    getFactsFromContact: GetFactsFromContact = .live
-  ) -> MakeContact {
-    MakeContact { data in
-      Contact(
-        data: data,
-        getId: { try getIdFromContact(data) },
-        getPublicKey: { try getPublicKeyFromContact(data) },
-        getFacts: { try getFactsFromContact(data) }
-      )
-    }
-  }
-}
diff --git a/Sources/XXClient/Models/Contact.swift b/Sources/XXClient/Models/Contact.swift
index d3143ff2..7ab58973 100644
--- a/Sources/XXClient/Models/Contact.swift
+++ b/Sources/XXClient/Models/Contact.swift
@@ -1,4 +1,5 @@
 import Foundation
+import XCTestDynamicOverlay
 
 public struct Contact {
   public init(
@@ -24,3 +25,30 @@ extension Contact: Equatable {
     lhs.data == rhs.data
   }
 }
+
+extension Contact {
+  public static func live(
+    _ data: Data,
+    getIdFromContact: GetIdFromContact = .live,
+    getPublicKeyFromContact: GetPublicKeyFromContact = .live,
+    getFactsFromContact: GetFactsFromContact = .live
+  ) -> Contact {
+    Contact(
+      data: data,
+      getId: { try getIdFromContact(data) },
+      getPublicKey: { try getPublicKeyFromContact(data) },
+      getFacts: { try getFactsFromContact(data) }
+    )
+  }
+}
+
+extension Contact {
+  public static func unimplemented(_ data: Data) -> Contact {
+    Contact(
+      data: data,
+      getId: XCTUnimplemented("\(Self.self).getId"),
+      getPublicKey: XCTUnimplemented("\(Self.self).getPublicKey"),
+      getFacts: XCTUnimplemented("\(Self.self).getFacts")
+    )
+  }
+}
-- 
GitLab