Skip to content

Commit 5a2da8c

Browse files
committed
test(file-provider): add testLockChangeDetectedByRemoteStateComparison.
Add simple unit test for isInSameDatabaseStoreableRemoteState. Use unique identifiers in lockToken test. Set creationDate in toNKFile() to match toItemMetadata(). Signed-off-by: Camila Ayres <hello@camilasan.com>
1 parent 15863a2 commit 5a2da8c

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

shell_integration/MacOSX/NextcloudFileProviderKit/Tests/Interface/MockRemoteItem.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ public class MockRemoteItem: Equatable {
132132
? NextcloudKit.shared.nkCommonInstance.rootFileName
133133
: trashbinOriginalLocation?.split(separator: "/").last?.toString() ?? name
134134
file.size = size
135-
file.date = creationDate
135+
file.creationDate = creationDate
136+
file.date = modificationDate
136137
file.directory = isRoot ? false : directory
138+
file.permissions = "RGDNVW"
137139
file.etag = versionIdentifier
138140
file.ocId = identifier
139141
file.fileId = identifier.replacingOccurrences(of: trashedItemIdSuffix, with: "")

shell_integration/MacOSX/NextcloudFileProviderKit/Tests/NextcloudFileProviderKitTests/EnumeratorTests.swift

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,4 +2022,87 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
20222022
)
20232023
}
20242024
}
2025+
2026+
func testLockChangeDetectedByRemoteStateComparison() {
2027+
var local = SendableItemMetadata(
2028+
ocId: "file1",
2029+
account: Self.account.ncKitAccount,
2030+
classFile: "",
2031+
contentType: "",
2032+
creationDate: Date(),
2033+
directory: false,
2034+
e2eEncrypted: false,
2035+
etag: "v1",
2036+
fileId: "file1",
2037+
fileName: "file.txt",
2038+
fileNameView: "file.txt",
2039+
ownerId: "",
2040+
ownerDisplayName: "",
2041+
path: "",
2042+
serverUrl: Self.account.davFilesUrl,
2043+
size: 0,
2044+
urlBase: Self.account.serverUrl,
2045+
user: Self.account.username,
2046+
userId: Self.account.id
2047+
)
2048+
var remote = local
2049+
2050+
XCTAssertTrue(local.isInSameDatabaseStoreableRemoteState(remote))
2051+
2052+
remote.lock = true
2053+
XCTAssertFalse(
2054+
local.isInSameDatabaseStoreableRemoteState(remote),
2055+
"A lock state change must be detected as a remote state difference"
2056+
)
2057+
2058+
local.lock = true
2059+
XCTAssertTrue(local.isInSameDatabaseStoreableRemoteState(remote))
2060+
}
2061+
2062+
func testLockTokenPreservedDuringTargetDepthRead() async throws {
2063+
let db = Self.dbManager.ncDatabase()
2064+
debugPrint(db)
2065+
2066+
let remoteFile = MockRemoteItem(
2067+
identifier: "lockTokenTestFile",
2068+
versionIdentifier: "V1",
2069+
name: "lockTokenTestFile.txt",
2070+
remotePath: Self.account.davFilesUrl + "/lockTokenTestFile.txt",
2071+
locked: true,
2072+
lockOwner: Self.account.username,
2073+
lockTimeOut: Date.now.advanced(by: 1_000_000),
2074+
account: Self.account.ncKitAccount,
2075+
username: Self.account.username,
2076+
userId: Self.account.id,
2077+
serverUrl: Self.account.serverUrl
2078+
)
2079+
2080+
rootItem.children = [remoteFile]
2081+
remoteFile.parent = rootItem
2082+
2083+
let remoteInterface = MockRemoteInterface(account: Self.account, rootItem: rootItem)
2084+
2085+
var fileMetadata = remoteFile.toItemMetadata(account: Self.account)
2086+
fileMetadata.lockToken = "local-lock-token-123"
2087+
fileMetadata.downloaded = true
2088+
Self.dbManager.addItemMetadata(fileMetadata)
2089+
2090+
let (_, _, _, _, _, readError) = await Enumerator.readServerUrl(
2091+
Self.account.davFilesUrl + "/lockTokenTestFile.txt",
2092+
account: Self.account,
2093+
remoteInterface: remoteInterface,
2094+
dbManager: Self.dbManager,
2095+
depth: .target,
2096+
log: FileProviderLogMock()
2097+
)
2098+
2099+
XCTAssertNil(readError)
2100+
2101+
let postRead = try XCTUnwrap(Self.dbManager.itemMetadata(ocId: "lockTokenTestFile"))
2102+
XCTAssertEqual(
2103+
postRead.lockToken,
2104+
"local-lock-token-123",
2105+
"lockToken must be preserved across target-depth reads"
2106+
)
2107+
}
20252108
}

0 commit comments

Comments
 (0)