Fixed remaining broken unit tests

pull/976/head
Morgan Pretty 1 year ago
parent 999ddfe50e
commit a5095b5965

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

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

@ -7,6 +7,21 @@ import Combine
import SessionUtil import SessionUtil
import SessionUtilitiesKit 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 // MARK: - LibSession
public extension LibSession { public extension LibSession {

@ -6,6 +6,7 @@ import GRDB
import Sodium import Sodium
import Curve25519Kit import Curve25519Kit
import SessionUtilitiesKit import SessionUtilitiesKit
import SessionSnodeKit
extension KeyPair: Mocked { extension KeyPair: Mocked {
static var mockValue: KeyPair = KeyPair( 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 { extension AnyPublisher: MockedGeneric where Failure == Error {
typealias Generic = Output typealias Generic = Output

Loading…
Cancel
Save