diff --git a/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift b/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift new file mode 100644 index 0000000000000000000000000000000000000000..724e33baf6992636b5c2ec8477be47aa06415fb1 --- /dev/null +++ b/Examples/xx-messenger/Sources/AppCore/SendImage/SendImage.swift @@ -0,0 +1,40 @@ +import Foundation +import XCTestDynamicOverlay +import XXClient +import XXMessengerClient +import XXModels + +public struct SendImage { + public typealias OnError = (Error) -> Void + public typealias Completion = () -> Void + + public var run: (Data, Data, @escaping OnError, @escaping Completion) -> Void + + public func callAsFunction( + _ image: Data, + to recipientId: Data, + onError: @escaping OnError, + completion: @escaping Completion + ) { + run(image, recipientId, onError, completion) + } +} + +extension SendImage { + public static func live( + messenger: Messenger, + db: DBManagerGetDB, + now: @escaping () -> Date + ) -> SendImage { + SendImage { image, recipientId, onError, completion in + // TODO: implement sending image + completion() + } + } +} + +extension SendImage { + public static let unimplemented = SendImage( + run: XCTUnimplemented("\(Self.self)") + ) +} diff --git a/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift b/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..147b63aca5193d58b5966e88edf59e149aa6ff88 --- /dev/null +++ b/Examples/xx-messenger/Tests/AppCoreTests/SendImage/SendImageTests.swift @@ -0,0 +1,41 @@ +import CustomDump +import XCTest +import XXClient +import XXMessengerClient +import XXModels +@testable import AppCore + +final class SendImageTests: XCTestCase { + func testSend() { + let image = "image-data".data(using: .utf8)! + let recipientId = "recipient-id".data(using: .utf8)! + + var actions: [Action] = [] + + let messenger: Messenger = .unimplemented + let db: DBManagerGetDB = .unimplemented + let now: () -> Date = Date.init + let send: SendImage = .live(messenger: messenger, db: db, now: now) + + actions = [] + send( + image, + to: recipientId, + onError: { error in + actions.append(.didFail(error as NSError)) + }, + completion: { + actions.append(.didComplete) + } + ) + + XCTAssertNoDifference(actions, [ + .didComplete + ]) + } +} + +private enum Action: Equatable { + case didFail(NSError) + case didComplete +}