Skip to content

Commit 5e0b1f6

Browse files
update connector for swift 6 in tests
1 parent 44c64d0 commit 5e0b1f6

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

Sources/PowerSync/Kotlin/KotlinTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PowerSyncKotlin
22

3-
typealias KotlinPowerSyncBackendConnector = PowerSyncKotlin.SwiftPowerSyncBackendConnector
3+
typealias KotlinPowerSyncBackendConnector = PowerSyncKotlin.PowerSyncBackendConnector
44
typealias KotlinPowerSyncCredentials = PowerSyncKotlin.PowerSyncCredentials
55
typealias KotlinPowerSyncDatabase = PowerSyncKotlin.PowerSyncDatabase
66

Sources/PowerSync/Kotlin/PowerSyncBackendConnectorAdapter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class PowerSyncBackendConnectorAdapter: KotlinPowerSyncBackendConnector,
2929
}
3030
}
3131

32-
override func __performUpload() async throws {
32+
override func __uploadData(database _: KotlinPowerSyncDatabase) async throws {
3333
do {
3434
// Pass the Swift DB protocal to the connector
3535
return try await swiftBackendConnector.uploadData(database: db)

Tests/PowerSyncTests/ConnectTests.swift

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class ConnectTests: XCTestCase {
3838
/// This is an example of specifying JSON client params.
3939
/// The test here just ensures that the Kotlin SDK accepts these params and does not crash
4040
try await database.connect(
41-
connector: PowerSyncBackendConnector(),
41+
connector: MockConnector(),
4242
params: [
4343
"foo": .string("bar"),
4444
]
@@ -50,67 +50,69 @@ final class ConnectTests: XCTestCase {
5050
XCTAssert(database.currentStatus.connecting == false)
5151

5252
try await database.connect(
53-
connector: PowerSyncBackendConnector()
53+
connector: MockConnector()
5454
)
5555

5656
try await waitFor(timeout: 10) {
5757
guard database.currentStatus.connecting == true else {
5858
throw WaitForMatchError.predicateFail(message: "Should be connecting")
5959
}
6060
}
61-
61+
6262
try await database.disconnect()
63-
63+
6464
try await waitFor(timeout: 10) {
6565
guard database.currentStatus.connecting == false else {
6666
throw WaitForMatchError.predicateFail(message: "Should not be connecting after disconnect")
6767
}
6868
}
6969
}
70-
70+
7171
func testSyncStatusUpdates() async throws {
7272
let expectation = XCTestExpectation(
7373
description: "Watch Sync Status"
7474
)
75-
75+
7676
let watchTask = Task { [database] in
7777
for try await _ in database!.currentStatus.asFlow() {
7878
expectation.fulfill()
7979
}
8080
}
81-
81+
8282
// Do some connecting operations
8383
try await database.connect(
84-
connector: PowerSyncBackendConnector()
84+
connector: MockConnector()
8585
)
86-
86+
8787
// We should get an update
8888
await fulfillment(of: [expectation], timeout: 5)
8989
watchTask.cancel()
9090
}
91-
91+
9292
func testSyncHTTPLogs() async throws {
9393
let expectation = XCTestExpectation(
9494
description: "Should log a request to the PowerSync endpoint"
9595
)
96-
96+
9797
let fakeUrl = "https://fakepowersyncinstance.fakepowersync.local"
98-
99-
class TestConnector: PowerSyncBackendConnector {
98+
99+
final class TestConnector: PowerSyncBackendConnectorProtocol {
100100
let url: String
101-
101+
102102
init(url: String) {
103103
self.url = url
104104
}
105-
106-
override func fetchCredentials() async throws -> PowerSyncCredentials? {
105+
106+
func fetchCredentials() async throws -> PowerSyncCredentials? {
107107
PowerSyncCredentials(
108108
endpoint: url,
109109
token: "123"
110110
)
111111
}
112+
113+
func uploadData(database _: PowerSyncDatabaseProtocol) async throws {}
112114
}
113-
115+
114116
try await database.connect(
115117
connector: TestConnector(url: fakeUrl),
116118
options: ConnectOptions(
@@ -126,9 +128,9 @@ final class ConnectTests: XCTestCase {
126128
)
127129
)
128130
)
129-
131+
130132
await fulfillment(of: [expectation], timeout: 5)
131-
133+
132134
try await database.disconnectAndClear()
133135
}
134136
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import PowerSync
22

3-
class MockConnector: PowerSyncBackendConnector {
4-
3+
final class MockConnector: PowerSyncBackendConnectorProtocol {
4+
func fetchCredentials() async throws -> PowerSync.PowerSyncCredentials? {
5+
return nil
6+
}
7+
8+
func uploadData(database _: any PowerSync.PowerSyncDatabaseProtocol) async throws {}
59
}

0 commit comments

Comments
 (0)