Skip to content
Snippets Groups Projects
Commit fb3ab8f2 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add SendImage to AppCore

parent 2bd04721
No related branches found
No related tags found
2 merge requests!124File transfers example,!102Release 1.0.0
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)")
)
}
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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment