Skip to content

Commit 3e46249

Browse files
committed
Work in progress: Fixed some compiler errors.
Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
1 parent 27efb92 commit 3e46249

5 files changed

Lines changed: 54 additions & 35 deletions

File tree

Sources/NextcloudFileProviderKit/Enumeration/RemoteChangeObserver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ extension RemoteChangeObserver: NextcloudKitDelegate {
500500
/// - Parameters:
501501
/// - completionHandler: An optional closure to call after the working set check completed.
502502
///
503-
func startWorkingSetCheck(completionHandler: (() -> Void)? = nil) {
503+
func startWorkingSetCheck(completionHandler: (@Sendable () -> Void)? = nil) {
504504
guard !workingSetCheckOngoing, !invalidated else {
505505
return
506506
}

Sources/NextcloudFileProviderKit/Utilities/RetrievedCapabilitiesActor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import NextcloudCapabilitiesKit
66

77
let CapabilitiesFetchInterval: TimeInterval = 30 * 60 // 30mins
88

9-
actor RetrievedCapabilitiesActor {
9+
actor RetrievedCapabilitiesActor: Sendable {
1010
static let shared = RetrievedCapabilitiesActor()
1111

1212
var ongoingFetches: Set<String> = []

Tests/Interface/MockRemoteInterface.swift

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
627627
return nil
628628
}
629629

630+
guard let account = mockedAccounts[account] else {
631+
return nil
632+
}
633+
630634
let sanitisedPath = sanitisedPath(remotePath, account: account)
631635

632636
guard sanitisedPath != "/" else {
@@ -666,7 +670,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
666670

667671
func parentItem(path: String, account: Account) -> MockRemoteItem? {
668672
let parentRemotePath = parentPath(path: path, account: account)
669-
return item(remotePath: parentRemotePath, account: account)
673+
return item(remotePath: parentRemotePath, account: account.ncKitAccount)
670674
}
671675

672676
func randomIdentifier() -> String {
@@ -908,7 +912,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
908912
return (account.ncKitAccount, nil, .urlError)
909913
}
910914

911-
guard let sourceItem = item(remotePath: remotePathSource, account: account) else {
915+
guard let sourceItem = item(remotePath: remotePathSource, account: account.ncKitAccount) else {
912916
print("Could not get item for remote path source\(remotePathSource)")
913917
return (account.ncKitAccount, nil, .urlError)
914918
}
@@ -997,9 +1001,9 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
9971001
fileNameLocalPath: String,
9981002
account: String,
9991003
options: NKRequestOptions,
1000-
requestHandler: @escaping (_ request: DownloadRequest) -> Void,
1001-
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void,
1002-
progressHandler: @escaping (_ progress: Progress) -> Void
1004+
requestHandler: @escaping (_ request: DownloadRequest) -> Void = { _ in },
1005+
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void = { _ in },
1006+
progressHandler: @escaping (_ progress: Progress) -> Void = { _ in }
10031007
) async -> (
10041008
account: String,
10051009
etag: String?,
@@ -1017,7 +1021,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
10171021
return (account, nil, nil, 0, nil, nil, .urlError)
10181022
}
10191023

1020-
guard let item = item(remotePath: serverUrlFileName, account: account) else {
1024+
guard let item = item(remotePath: serverUrlFileName, account: account.ncKitAccount) else {
10211025
return (account.ncKitAccount, nil, nil, 0, nil, nil, .urlError)
10221026
}
10231027

@@ -1034,11 +1038,11 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
10341038
}
10351039
} catch {
10361040
print("Could not write item data: \(error)")
1037-
return (account, nil, nil, 0, nil, nil, .urlError)
1041+
return (account.ncKitAccount, nil, nil, 0, nil, nil, .urlError)
10381042
}
10391043

10401044
return (
1041-
account,
1045+
account.ncKitAccount,
10421046
item.versionIdentifier,
10431047
item.creationDate as Date,
10441048
item.size,
@@ -1073,7 +1077,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
10731077
// Call the enumerate call handler if it exists
10741078
enumerateCallHandler?(remotePath, depth, showHiddenFiles, includeHiddenFiles, requestBody, account, options, taskHandler)
10751079

1076-
guard let item = item(remotePath: remotePath, account: account) else {
1080+
guard let item = item(remotePath: remotePath, account: account.ncKitAccount) else {
10771081
print("Item at \(remotePath) not found.")
10781082
return (
10791083
account.ncKitAccount,
@@ -1166,7 +1170,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
11661170
options _: NKRequestOptions = .init(),
11671171
taskHandler _: @escaping (URLSessionTask) -> Void = { _ in }
11681172
) async -> (account: String, response: HTTPURLResponse?, error: NKError) {
1169-
guard let item = item(remotePath: remotePath, account: account) else {
1173+
guard let item = item(remotePath: remotePath, account: account.ncKitAccount) else {
11701174
return (account.ncKitAccount, nil, .urlError)
11711175
}
11721176

@@ -1185,7 +1189,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
11851189
}
11861190

11871191
public func lockUnlockFile(serverUrlFileName: String, type _: NKLockType?, shouldLock: Bool, account: Account, options _: NKRequestOptions, taskHandler _: @escaping (URLSessionTask) -> Void) async throws -> NKLock? {
1188-
guard let item = item(remotePath: serverUrlFileName, account: account) else {
1192+
guard let item = item(remotePath: serverUrlFileName, account: account.ncKitAccount) else {
11891193
throw NKError.urlError
11901194
}
11911195

@@ -1206,8 +1210,11 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
12061210
responseData: AFDataResponse<Data>?,
12071211
error: NKError
12081212
) {
1209-
guard let rootTrashItem else { return (account.ncKitAccount, [], nil, .invalidData) }
1210-
return (account.ncKitAccount, rootTrashItem.children.map { $0.toNKTrash() }, nil, .success)
1213+
guard let rootTrashItem else {
1214+
return (account, [], nil, .invalidData)
1215+
}
1216+
1217+
return (account, rootTrashItem.children.map { $0.toNKTrash() }, nil, .success)
12111218
}
12121219

12131220
public func restoreFromTrash(
@@ -1254,7 +1261,7 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
12541261
return Capabilities(data: capsData ?? Data())
12551262
}
12561263

1257-
func getUserProfileAsync(
1264+
public func getUserProfileAsync(
12581265
account: String,
12591266
options: NKRequestOptions,
12601267
taskHandler: @Sendable @escaping (_ task: URLSessionTask) -> Void
@@ -1264,11 +1271,16 @@ public class MockRemoteInterface: RemoteInterface, @unchecked Sendable {
12641271
responseData: AFDataResponse<Data>?,
12651272
error: NKError
12661273
) {
1274+
guard let account = mockedAccounts[account] else {
1275+
return (account, nil, nil, .urlError)
1276+
}
1277+
12671278
let profile = NKUserProfile()
12681279
profile.address = account.serverUrl
12691280
profile.backend = "mock"
12701281
profile.displayName = account.ncKitAccount
12711282
profile.userId = account.id
1283+
12721284
return (account.ncKitAccount, profile, nil, .success)
12731285
}
12741286

Tests/InterfaceTests/MockRemoteInterfaceTests.swift

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
7676

7777
XCTAssertEqual(
7878
remoteInterface.item(
79-
remotePath: Self.account.davFilesUrl + "/a/b/target", account: Self.account
79+
remotePath: Self.account.davFilesUrl + "/a/b/target", account: Self.account.ncKitAccount
8080
), targetItem
8181
)
8282
}
@@ -85,7 +85,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
8585
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
8686
debugPrint(remoteInterface)
8787
XCTAssertEqual(
88-
remoteInterface.item(remotePath: Self.account.davFilesUrl, account: Self.account), rootItem
88+
remoteInterface.item(remotePath: Self.account.davFilesUrl, account: Self.account.ncKitAccount), rootItem
8989
)
9090
}
9191

@@ -136,12 +136,12 @@ final class MockRemoteInterfaceTests: XCTestCase {
136136
)
137137
XCTAssertEqual(resultA_B.error, .success)
138138

139-
let itemA = remoteInterface.item(remotePath: newFolderAPath, account: Self.account)
139+
let itemA = remoteInterface.item(remotePath: newFolderAPath, account: Self.account.ncKitAccount)
140140
XCTAssertNotNil(itemA)
141141
XCTAssertEqual(itemA?.name, "A")
142142
XCTAssertTrue(itemA?.directory ?? false)
143143

144-
let itemA_B = remoteInterface.item(remotePath: newFolderA_BPath, account: Self.account)
144+
let itemA_B = remoteInterface.item(remotePath: newFolderA_BPath, account: Self.account.ncKitAccount)
145145
XCTAssertNotNil(itemA_B)
146146
XCTAssertEqual(itemA_B?.name, "B")
147147
XCTAssertTrue(itemA_B?.directory ?? false)
@@ -161,7 +161,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
161161
XCTAssertEqual(result.remoteError, .success)
162162

163163
let remoteItem = remoteInterface.item(
164-
remotePath: Self.account.davFilesUrl + "/file.txt", account: Self.account
164+
remotePath: Self.account.davFilesUrl + "/file.txt", account: Self.account.ncKitAccount
165165
)
166166
XCTAssertNotNil(remoteItem)
167167

@@ -187,11 +187,11 @@ final class MockRemoteInterfaceTests: XCTestCase {
187187
XCTAssertEqual(result.remoteError, .success)
188188

189189
let remoteItem = remoteInterface.item(
190-
remotePath: Self.account.davFilesUrl + "/file.txt", account: Self.account
190+
remotePath: Self.account.davFilesUrl + "/file.txt", account: Self.account.ncKitAccount
191191
)
192192
XCTAssertNotNil(remoteItem)
193193
let remoteItemIncorrectFileName = remoteInterface.item(
194-
remotePath: Self.account.davFilesUrl + "/" + fileName, account: Self.account
194+
remotePath: Self.account.davFilesUrl + "/" + fileName, account: Self.account.ncKitAccount
195195
)
196196
XCTAssertNil(remoteItemIncorrectFileName)
197197
}
@@ -636,7 +636,7 @@ final class MockRemoteInterfaceTests: XCTestCase {
636636
XCTAssertEqual(itemA_C_D.remotePath, Self.account.trashUrl + "/c (trashed)/d")
637637
}
638638

639-
func testTrashedItems() async {
639+
func testTrashedItems() async throws {
640640
let remoteInterface = MockRemoteInterface(rootItem: rootItem, rootTrashItem: rootTrashItem)
641641
debugPrint(remoteInterface)
642642
let itemA = MockRemoteItem(
@@ -665,15 +665,18 @@ final class MockRemoteInterfaceTests: XCTestCase {
665665
itemA.parent = rootTrashItem
666666
itemB.parent = rootTrashItem
667667

668-
let (_, items, _, error) = await remoteInterface.trashedItems(account: Self.account)
668+
let (_, items, _, error) = await remoteInterface.listingTrashAsync(filename: nil, showHiddenFiles: true, account: Self.account.ncKitAccount, options: .init(), taskHandler: { _ in })
669+
669670
XCTAssertEqual(error, .success)
670-
XCTAssertEqual(items.count, 2)
671-
XCTAssertEqual(items[0].fileName, "a (trashed)")
672-
XCTAssertEqual(items[1].fileName, "b (trashed)")
673-
XCTAssertEqual(items[0].trashbinFileName, "a")
674-
XCTAssertEqual(items[1].trashbinFileName, "b")
675-
XCTAssertEqual(items[0].ocId, itemA.identifier)
676-
XCTAssertEqual(items[1].ocId, itemB.identifier)
671+
672+
let unwrappedItems = try XCTUnwrap(items)
673+
XCTAssertEqual(unwrappedItems.count, 2)
674+
XCTAssertEqual(unwrappedItems[0].fileName, "a (trashed)")
675+
XCTAssertEqual(unwrappedItems[1].fileName, "b (trashed)")
676+
XCTAssertEqual(unwrappedItems[0].trashbinFileName, "a")
677+
XCTAssertEqual(unwrappedItems[1].trashbinFileName, "b")
678+
XCTAssertEqual(unwrappedItems[0].ocId, itemA.identifier)
679+
XCTAssertEqual(unwrappedItems[1].ocId, itemB.identifier)
677680
}
678681

679682
// The server will return ocIds as fileIds. To try to test the item modification steps' handling
@@ -847,9 +850,13 @@ final class MockRemoteInterfaceTests: XCTestCase {
847850
func testFetchUserProfile() async {
848851
let remoteInterface = MockRemoteInterface(rootItem: rootItem)
849852
debugPrint(remoteInterface)
850-
let (account, profile, _, error) = await remoteInterface.fetchUserProfile(
851-
account: Self.account
853+
854+
let (account, profile, _, error) = await remoteInterface.getUserProfileAsync(
855+
account: Self.account.ncKitAccount,
856+
options: .init(),
857+
taskHandler: { _ in }
852858
)
859+
853860
XCTAssertEqual(error, .success)
854861
XCTAssertEqual(account, Self.account.ncKitAccount)
855862
XCTAssertNotNil(profile)

Tests/NextcloudFileProviderKitTests/RetrievedCapabilitiesActorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct RetrievedCapabilitiesActorTests {
2020

2121
// We call the public API.
2222
await actor.setCapabilities(forAccount: account1, capabilities: caps, retrievedAt: specificDate)
23-
let setCaps = await actor.data[account1]
23+
let setCaps = await actor.getCapabilities(for: account1)
2424

2525
#expect(setCaps?.retrievedAt == specificDate)
2626
#expect(setCaps?.capabilities != nil)

0 commit comments

Comments
 (0)