Skip to content

Commit 908c4e3

Browse files
committed
test: fix JSONRPCEngine mock and ControllerAccount test typings\n\n- Replace wrapper MockConnection with subclass of MockJSONRPCEngine\n- Import SSFModels and type Cuckoo matchers in ControllerAccountTests\n- Align wireframe present signatures to SheetAlertPresentable types
Signed-off-by: William Richter <[email protected]>
1 parent 478f1b9 commit 908c4e3

File tree

2 files changed

+10
-73
lines changed

2 files changed

+10
-73
lines changed
Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,5 @@
11
import Foundation
22
@testable import fearless
3-
import SSFUtils
43

5-
final class MockConnection {
6-
let internalConnection = MockJSONRPCEngine()
7-
}
8-
9-
extension MockConnection: JSONRPCEngine {
10-
var url: URL? {
11-
get { internalConnection.url }
12-
set { internalConnection.url = newValue }
13-
}
14-
15-
var pendingEngineRequests: [JSONRPCRequest] { internalConnection.pendingEngineRequests }
16-
17-
func reconnect(url: URL) {
18-
internalConnection.reconnect(url: url)
19-
}
20-
21-
func connectIfNeeded() {
22-
internalConnection.connectIfNeeded()
23-
}
24-
25-
func disconnectIfNeeded() {
26-
internalConnection.disconnectIfNeeded()
27-
}
28-
29-
func connect(with pendingRequests: [JSONRPCRequest]) {
30-
// Forwarding connect helper (if needed in future tests)
31-
// No-op for now; tests use call/subscribe directly
32-
}
33-
34-
func generateRequestId() -> UInt16 { internalConnection.generateRequestId() }
35-
36-
func addSubscription(_ subscription: JSONRPCSubscribing) { internalConnection.addSubscription(subscription) }
37-
38-
func callMethod<P, T>(
39-
_ method: String,
40-
params: P?,
41-
options: JSONRPCOptions,
42-
completion closure: ((Result<T, Error>) -> Void)?
43-
) throws -> UInt16 where P: Encodable, T: Decodable {
44-
try internalConnection.callMethod(
45-
method,
46-
params: params,
47-
options: options,
48-
completion: closure
49-
)
50-
}
51-
52-
func subscribe<P, T>(
53-
_ method: String,
54-
params: P?,
55-
updateClosure: @escaping (T) -> Void,
56-
failureClosure: @escaping (Error, Bool) -> Void
57-
) throws -> UInt16 where P: Encodable, T: Decodable {
58-
try internalConnection.subscribe(
59-
method,
60-
params: params,
61-
updateClosure: updateClosure,
62-
failureClosure: failureClosure
63-
)
64-
}
65-
66-
func cancelForIdentifier(_ identifier: UInt16) {
67-
internalConnection.cancelForIdentifier(identifier)
68-
}
69-
}
4+
// Use generated Cuckoo mock directly to conform to current JSONRPCEngine
5+
final class MockConnection: MockJSONRPCEngine {}

fearlessTests/Modules/ControllerAccount/ControllerAccountTests.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import XCTest
22
import Cuckoo
33
import RobinHood
44
import SSFUtils
5+
import SSFModels
56
import SoraKeystore
67
import SoraFoundation
78
@testable import fearless
@@ -52,14 +53,14 @@ class ControllerAccountTests: XCTestCase {
5253
when(stub).showConfirmation(
5354
from: any(ControllerBackedProtocol?.self),
5455
controllerAccountItem: any(fearless.ChainAccountResponse.self),
55-
asset: any(AssetModel.self),
56-
chain: any(ChainModel.self),
56+
asset: any(SSFModels.AssetModel.self),
57+
chain: any(SSFModels.ChainModel.self),
5758
selectedAccount: any(fearless.MetaAccountModel.self)
5859
).then { _ in
5960
showConfirmationExpectation.fulfill()
6061
}
6162

62-
when(stub).present(viewModel: any(), from: any()).thenDoNothing()
63+
when(stub).present(viewModel: any(SheetAlertPresentableViewModel.self), from: any(ControllerBackedProtocol?.self)).thenDoNothing()
6364
}
6465
stub(viewModelFactory) { stub in
6566
when(stub).createViewModel(
@@ -128,11 +129,11 @@ class ControllerAccountTests: XCTestCase {
128129
)
129130
stub(wireframe) { stub in
130131
when(stub).present(
131-
message: any(String.self),
132-
title: any(String?.self),
133-
closeAction: any(String.self),
132+
message: any(String?.self),
133+
title: any(String.self),
134+
closeAction: any(String?.self),
134135
from: any(ControllerBackedProtocol?.self),
135-
actions: any([UIAlertAction].self)
136+
actions: any([SheetAlertPresentableAction].self)
136137
).then { _ in
137138
showErrorAlertExpectation.fulfill()
138139
}

0 commit comments

Comments
 (0)