Skip to content

Commit 7b26ae4

Browse files
committed
fix: Unit tests.
Signed-off-by: Iva Horn <iva.horn@icloud.com>
1 parent 98d6a06 commit 7b26ae4

4 files changed

Lines changed: 12 additions & 32 deletions

File tree

Sources/NextcloudFileProviderKit/Enumeration/Enumerator+SyncEngine.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ extension Enumerator {
6262
}
6363

6464
// STORE DATA FOR CURRENTLY SCANNED DIRECTORY
65-
assert(directoryMetadata.directory)
65+
guard directoryMetadata.directory else {
66+
logger.error("Expected directory metadata but received file metadata for serverUrl: \(serverUrl)")
67+
return (nil, nil, nil, nil, .invalidData)
68+
}
6669

6770
if let existingMetadata = dbManager.itemMetadata(ocId: directoryMetadata.ocId) {
6871
directoryMetadata.downloaded = existingMetadata.downloaded
6972
directoryMetadata.keepDownloaded = existingMetadata.keepDownloaded
7073
}
71-
74+
7275
directoryMetadata.visitedDirectory = true
7376

7477
metadatas.insert(directoryMetadata, at: 0)
@@ -214,7 +217,7 @@ extension Enumerator {
214217
let (
215218
allMetadatas, newMetadatas, updatedMetadatas, deletedMetadatas, readError
216219
) = await handleDepth1ReadFileOrFolder(
217-
serverUrl: serverUrl,
220+
serverUrl: serverUrl,
218221
account: account,
219222
dbManager: dbManager,
220223
files: files,

Tests/Interface/MockRemoteItem.swift

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ public class MockRemoteItem: Equatable {
2323
public var data: Data?
2424
public var locked: Bool
2525
public var lockOwner: String
26-
public var lockOwnerEditor: String
27-
public var lockOwnerType: Int
28-
public var lockOwnerDisplayName: String
29-
public var lockTime: Date?
3026
public var lockTimeOut: Date?
31-
public var lockToken: String?
3227
public var size: Int64 { Int64(data?.count ?? 0) }
3328
public var account: String
3429
public var username: String
@@ -45,12 +40,7 @@ public class MockRemoteItem: Equatable {
4540
lhs.directory == rhs.directory &&
4641
lhs.locked == rhs.locked &&
4742
lhs.lockOwner == rhs.lockOwner &&
48-
lhs.lockOwnerEditor == rhs.lockOwnerEditor &&
49-
lhs.lockOwnerType == rhs.lockOwnerType &&
50-
lhs.lockOwnerDisplayName == rhs.lockOwnerDisplayName &&
51-
lhs.lockTime == rhs.lockTime &&
5243
lhs.lockTimeOut == rhs.lockTimeOut &&
53-
lhs.lockToken == rhs.lockToken &&
5444
lhs.data == rhs.data &&
5545
lhs.size == rhs.size &&
5646
lhs.creationDate == rhs.creationDate &&
@@ -101,12 +91,7 @@ public class MockRemoteItem: Equatable {
10191
data: Data? = nil,
10292
locked: Bool = false,
10393
lockOwner: String = "",
104-
lockOwnerEditor: String = "",
105-
lockOwnerDisplayName: String = "",
106-
lockOwnerType: Int = 0,
107-
lockTime: Date? = nil,
10894
lockTimeOut: Date? = nil,
109-
lockToken: String? = nil,
11095
account: String,
11196
username: String,
11297
userId: String,
@@ -123,12 +108,7 @@ public class MockRemoteItem: Equatable {
123108
self.data = data
124109
self.locked = locked
125110
self.lockOwner = lockOwner
126-
self.lockOwnerEditor = lockOwnerEditor
127-
self.lockOwnerDisplayName = lockOwnerDisplayName
128-
self.lockOwnerType = lockOwnerType
129-
self.lockTime = lockTime
130111
self.lockTimeOut = lockTimeOut
131-
self.lockToken = lockToken
132112
self.account = account
133113
self.username = username
134114
self.userId = userId
@@ -155,7 +135,9 @@ public class MockRemoteItem: Equatable {
155135
file.user = username
156136
file.userId = userId
157137
file.urlBase = serverUrl
158-
file.lock = NKLock(owner: lockOwner, ownerEditor: lockOwnerEditor, ownerType: NKLockType(rawValue: lockOwnerType)!, ownerDisplayName: lockOwnerDisplayName, time: lockTime, timeOut: lockTimeOut, token: lockToken)
138+
file.lock = locked
139+
file.lockOwner = lockOwner
140+
file.lockTimeOut = lockTimeOut
159141
file.trashbinFileName = name
160142
file.trashbinOriginalLocation = trashbinOriginalLocation ?? ""
161143
return file
@@ -211,7 +193,7 @@ public class MockRemoteItem: Equatable {
211193
lockOwner: lockOwner,
212194
lockOwnerType: lockOwner.isEmpty ? 0 : 1,
213195
lockOwnerDisplayName: lockOwner == account.username ? account.username : "other user",
214-
lockTime: lockTime, // Default as not set in original code
196+
lockTime: nil, // Default as not set in original code
215197
lockTimeOut: lockTimeOut,
216198
path: "", // Placeholder as not set in original code
217199
serverUrl: trimmedServerUrl,

Tests/NextcloudFileProviderKitTests/ItemModifyTests.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,11 +1453,7 @@ final class ItemModifyTests: NextcloudFileProviderKitTestCase {
14531453
dbManager: Self.dbManager
14541454
)
14551455

1456-
if #available(macOS 13.0, *) {
1457-
XCTAssertEqual(error as? NSFileProviderError, NSFileProviderError(.excludedFromSync))
1458-
} else {
1459-
XCTAssertNil(error)
1460-
}
1456+
XCTAssertNil(error)
14611457
XCTAssertEqual(modifiedItem?.itemIdentifier, lockItem.itemIdentifier)
14621458
XCTAssertEqual(modifiedItem?.filename, modifiedMetadata.fileName)
14631459
XCTAssertEqual(modifiedItem?.documentSize?.intValue, tempData.count)

Tests/NextcloudFileProviderKitTests/RemoteChangeObserverEtagOptimizationTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ final class RemoteChangeObserverEtagOptimizationTests: NextcloudFileProviderKitT
171171
// The key optimization we want: the same folder with unchanged etag shouldn't be
172172
// enumerated repeatedly. Ideally, it should be enumerated only once.
173173
// However, without optimization, it might be enumerated 3 times (once per working set check)
174-
XCTAssertLessThanOrEqual(customersEnumerateCount, 1,
175-
"Customers folder with unchanged etag should not be enumerated repeatedly")
174+
XCTAssertLessThanOrEqual(customersEnumerateCount, 1, "Customers folder with unchanged etag should not be enumerated repeatedly")
176175
}
177176
}

0 commit comments

Comments
 (0)