From 42f41741011fe99b33b0b7c6f01530d39b1bfb64 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Sun, 16 Oct 2022 23:22:26 +0200
Subject: [PATCH] Revert "Remove MessengerReceiveFile function"

This reverts commit ff222fa40d2c70d73bee5fdc5fd4ec8243480f82.
---
 .../Functions/MessengerReceiveFile.swift      | 32 +++++++++++++++++++
 .../Messenger/Messenger.swift                 |  7 ++--
 .../Functions/MessengerReceiveFileTests.swift | 27 ++++++++++++++++
 3 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift
 create mode 100644 Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift

diff --git a/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift b/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift
new file mode 100644
index 00000000..91230c63
--- /dev/null
+++ b/Sources/XXMessengerClient/Messenger/Functions/MessengerReceiveFile.swift
@@ -0,0 +1,32 @@
+import Foundation
+import XCTestDynamicOverlay
+import XXClient
+
+public struct MessengerReceiveFile {
+  public enum Error: Swift.Error, Equatable {
+    case notConnected
+  }
+
+  public var run: () throws -> Void
+
+  public func callAsFunction() throws -> Void {
+    try run()
+  }
+}
+
+extension MessengerReceiveFile {
+  public static func live(_ env: MessengerEnvironment) -> MessengerReceiveFile {
+    MessengerReceiveFile {
+      guard let e2e = env.e2e() else {
+        throw Error.notConnected
+      }
+      // TODO: implement receiving file
+    }
+  }
+}
+
+extension MessengerReceiveFile {
+  public static let unimplemented = MessengerReceiveFile(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
diff --git a/Sources/XXMessengerClient/Messenger/Messenger.swift b/Sources/XXMessengerClient/Messenger/Messenger.swift
index 2c8ef5d5..793daab0 100644
--- a/Sources/XXMessengerClient/Messenger/Messenger.swift
+++ b/Sources/XXMessengerClient/Messenger/Messenger.swift
@@ -42,6 +42,7 @@ public struct Messenger {
   public var startLogging: MessengerStartLogging
   public var startFileTransfer: MessengerStartFileTransfer
   public var sendFile: MessengerSendFile
+  public var receiveFile: MessengerReceiveFile
 }
 
 extension Messenger {
@@ -87,7 +88,8 @@ extension Messenger {
       setLogLevel: .live(env),
       startLogging: .live(env),
       startFileTransfer: .live(env),
-      sendFile: .live(env)
+      sendFile: .live(env),
+      receiveFile: .live(env)
     )
   }
 }
@@ -134,6 +136,7 @@ extension Messenger {
     setLogLevel: .unimplemented,
     startLogging: .unimplemented,
     startFileTransfer: .unimplemented,
-    sendFile: .unimplemented
+    sendFile: .unimplemented,
+    receiveFile: .unimplemented
   )
 }
diff --git a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift
new file mode 100644
index 00000000..ef9b5864
--- /dev/null
+++ b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerReceiveFileTests.swift
@@ -0,0 +1,27 @@
+import CustomDump
+import XCTest
+import XXClient
+@testable import XXMessengerClient
+
+final class MessengerReceiveFileTests: XCTestCase {
+  func testReceiveFile() throws {
+    var env: MessengerEnvironment = .unimplemented
+    env.e2e.get = { .unimplemented }
+    let receiveFile: MessengerReceiveFile = .live(env)
+
+    try receiveFile()
+  }
+
+  func testReceiveFileWhenNotConnected() {
+    var env: MessengerEnvironment = .unimplemented
+    env.e2e.get = { nil }
+    let receiveFile: MessengerReceiveFile = .live(env)
+
+    XCTAssertThrowsError(try receiveFile()) { error in
+      XCTAssertNoDifference(
+        error as? MessengerReceiveFile.Error,
+        MessengerReceiveFile.Error.notConnected
+      )
+    }
+  }
+}
-- 
GitLab