Fixed remaining broken unit tests

pull/976/head
Morgan Pretty 3 weeks ago
parent 999ddfe50e
commit a5095b5965

@ -1169,8 +1169,11 @@ public final class OpenGroupManager {
.eraseToAnyPublisher()
case .none:
return LibSession
.downloadFile(from: destination)
return dependencies.network
.send(
.downloadFile(from: destination),
using: dependencies
)
.map { _, imageData in imageData }
.eraseToAnyPublisher()
}

@ -3148,16 +3148,22 @@ class OpenGroupManagerSpec: QuickSpec {
mockNetwork
.when {
$0.send(
.onionRequest(
URLRequest(url: URL(string: "https://open.getsession.org/room/test2/file/12")!),
to: OpenGroupAPI.defaultServer,
with: OpenGroupAPI.defaultServerPublicKey,
timeout: Network.fileDownloadTimeout
.downloadFile(
from: .server(
url: URL(string: "https://open.getsession.org/room/test2/file/12")!,
method: .get,
headers: nil,
x25519PublicKey: TestConstants.publicKey
)
),
using: dependencies
)
}
.thenReturn(MockNetwork.response(data: Data([1, 2, 3])))
.thenReturn(
Just((MockResponseInfo.mockValue, Data([1, 2, 3])))
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
)
let testDate: Date = Date(timeIntervalSince1970: 1234567890)
dependencies.dateNow = testDate
@ -3189,8 +3195,12 @@ class OpenGroupManagerSpec: QuickSpec {
context("when getting a room image") {
beforeEach {
mockNetwork
.when { $0.send(.onionRequest(any(), to: any(), with: any()), using: dependencies) }
.thenReturn(MockNetwork.response(data: Data([1, 2, 3])))
.when { $0.send(.downloadFile(from: any()), using: dependencies) }
.thenReturn(
Just((MockResponseInfo.mockValue, Data([1, 2, 3])))
.setFailureType(to: Error.self)
.eraseToAnyPublisher()
)
mockUserDefaults
.when { (defaults: inout any UserDefaultsType) -> Any? in defaults.object(forKey: any()) }

@ -7,6 +7,21 @@ import Combine
import SessionUtil
import SessionUtilitiesKit
public extension Network.RequestType {
// FIXME: Clean up the network/libSession injection interface
static func downloadFile(
from destination: Network.Destination
) -> Network.RequestType<Data> {
return Network.RequestType(
id: "downloadFile",
url: "\(destination)",
args: [destination]
) { _ in
LibSession.downloadFile(from: destination).eraseToAnyPublisher()
}
}
}
// MARK: - LibSession
public extension LibSession {

@ -6,6 +6,7 @@ import GRDB
import Sodium
import Curve25519Kit
import SessionUtilitiesKit
import SessionSnodeKit
extension KeyPair: Mocked {
static var mockValue: KeyPair = KeyPair(
@ -47,6 +48,15 @@ extension Network.RequestType: MockedGeneric {
}
}
extension Network.Destination: Mocked {
static var mockValue: Network.Destination = Network.Destination.server(
url: URL(string: "https://oxen.io")!,
method: .get,
headers: nil,
x25519PublicKey: ""
)
}
extension AnyPublisher: MockedGeneric where Failure == Error {
typealias Generic = Output

Loading…
Cancel
Save