@@ -2023,116 +2023,51 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
20232023 }
20242024 }
20252025
2026- func testLockChangeInNestedFileDetectedDuringWorkingSetEnumeration( ) async throws {
2027- let db = Self . dbManager. ncDatabase ( )
2028- debugPrint ( db)
2029-
2030- let lockTestFolder = MockRemoteItem (
2031- identifier: " lockTestFolder " ,
2032- versionIdentifier: " LTF_V1 " ,
2033- name: " lockTestFolder " ,
2034- remotePath: Self . account. davFilesUrl + " /lockTestFolder " ,
2035- directory: true ,
2036- account: Self . account. ncKitAccount,
2037- username: Self . account. username,
2038- userId: Self . account. id,
2039- serverUrl: Self . account. serverUrl
2040- )
2041-
2042- let lockTestChildFolder = MockRemoteItem (
2043- identifier: " lockTestChildFolder " ,
2044- versionIdentifier: " LTCF_V1 " ,
2045- name: " lockTestChildFolder " ,
2046- remotePath: Self . account. davFilesUrl + " /lockTestFolder/lockTestChildFolder " ,
2047- directory: true ,
2048- account: Self . account. ncKitAccount,
2049- username: Self . account. username,
2050- userId: Self . account. id,
2051- serverUrl: Self . account. serverUrl
2052- )
2053-
2054- let lockTestNestedFile = MockRemoteItem (
2055- identifier: " lockTestNestedFile " ,
2056- versionIdentifier: " LTNF_V1 " ,
2057- name: " lockTestNestedFile.txt " ,
2058- remotePath: Self . account. davFilesUrl + " /lockTestFolder/lockTestChildFolder/lockTestNestedFile.txt " ,
2059- locked: true ,
2060- lockOwner: " otherUser " ,
2061- lockTimeOut: Date . now. advanced ( by: 1_000_000 ) ,
2026+ func testLockChangeDetectedByRemoteStateComparison( ) {
2027+ var local = SendableItemMetadata (
2028+ ocId: " file1 " ,
20622029 account: Self . account. ncKitAccount,
2063- username: Self . account. username,
2064- userId: Self . account. id,
2065- serverUrl: Self . account. serverUrl
2066- )
2067-
2068- rootItem. children = [ lockTestFolder]
2069- lockTestFolder. parent = rootItem
2070- lockTestFolder. children = [ lockTestChildFolder]
2071- lockTestChildFolder. parent = lockTestFolder
2072- lockTestChildFolder. children = [ lockTestNestedFile]
2073- lockTestNestedFile. parent = lockTestChildFolder
2074-
2075- let remoteInterface = MockRemoteInterface ( account: Self . account, rootItem: rootItem)
2076-
2077- var folderMetadata = lockTestFolder. toItemMetadata ( account: Self . account)
2078- folderMetadata. visitedDirectory = true
2079- Self . dbManager. addItemMetadata ( folderMetadata)
2080-
2081- var childFolderMetadata = lockTestChildFolder. toItemMetadata ( account: Self . account)
2082- childFolderMetadata. visitedDirectory = true
2083- Self . dbManager. addItemMetadata ( childFolderMetadata)
2084-
2085- var nestedFileMetadata = lockTestNestedFile. toItemMetadata ( account: Self . account)
2086- nestedFileMetadata. downloaded = true
2087- nestedFileMetadata. lock = false
2088- nestedFileMetadata. lockOwner = " "
2089- nestedFileMetadata. lockTimeOut = nil
2090- Self . dbManager. addItemMetadata ( nestedFileMetadata)
2091-
2092- let anchorDate = Date ( ) . addingTimeInterval ( - 300 )
2093- let formatter = ISO8601DateFormatter ( )
2094- let anchor = try NSFileProviderSyncAnchor ( XCTUnwrap ( formatter. string ( from: anchorDate) . data ( using: . utf8) ) )
2095-
2096- let enumerator = try Enumerator (
2097- enumeratedItemIdentifier: . workingSet,
2098- account: Self . account,
2099- remoteInterface: remoteInterface,
2100- dbManager: Self . dbManager,
2101- log: FileProviderLogMock ( )
2102- )
2103-
2104- let observer = MockChangeObserver ( enumerator: enumerator)
2105- try await observer. enumerateChanges ( from: anchor)
2106-
2107- XCTAssertNil ( observer. error)
2108-
2109- let dbNestedFile = try XCTUnwrap (
2110- Self . dbManager. itemMetadata ( ocId: lockTestNestedFile. identifier)
2111- )
2112- XCTAssertTrue (
2113- dbNestedFile. lock,
2114- " Lock change on nested file should be detected during working set enumeration "
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 "
21152056 )
2116- XCTAssertEqual ( dbNestedFile. lockOwner, " otherUser " )
21172057
2118- let nestedFileReported = observer. changedItems. contains {
2119- $0. itemIdentifier. rawValue == lockTestNestedFile. identifier
2120- }
2121- XCTAssertTrue (
2122- nestedFileReported,
2123- " Nested file with lock change should be reported as changed "
2124- )
2058+ local. lock = true
2059+ XCTAssertTrue ( local. isInSameDatabaseStoreableRemoteState ( remote) )
21252060 }
21262061
21272062 func testLockTokenPreservedDuringTargetDepthRead( ) async throws {
21282063 let db = Self . dbManager. ncDatabase ( )
21292064 debugPrint ( db)
21302065
21312066 let remoteFile = MockRemoteItem (
2132- identifier: " lockedFile " ,
2067+ identifier: " lockTokenTestFile " ,
21332068 versionIdentifier: " V1 " ,
2134- name: " lockedFile .txt" ,
2135- remotePath: Self . account. davFilesUrl + " /lockedFile .txt " ,
2069+ name: " lockTokenTestFile .txt" ,
2070+ remotePath: Self . account. davFilesUrl + " /lockTokenTestFile .txt " ,
21362071 locked: true ,
21372072 lockOwner: Self . account. username,
21382073 lockTimeOut: Date . now. advanced ( by: 1_000_000 ) ,
@@ -2152,11 +2087,8 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
21522087 fileMetadata. downloaded = true
21532088 Self . dbManager. addItemMetadata ( fileMetadata)
21542089
2155- let preRead = try XCTUnwrap ( Self . dbManager. itemMetadata ( ocId: " lockedFile " ) )
2156- XCTAssertEqual ( preRead. lockToken, " local-lock-token-123 " )
2157-
2158- let ( metadatas, _, _, _, _, readError) = await Enumerator . readServerUrl (
2159- Self . account. davFilesUrl + " /lockedFile.txt " ,
2090+ let ( _, _, _, _, _, readError) = await Enumerator . readServerUrl (
2091+ Self . account. davFilesUrl + " /lockTokenTestFile.txt " ,
21602092 account: Self . account,
21612093 remoteInterface: remoteInterface,
21622094 dbManager: Self . dbManager,
@@ -2165,14 +2097,12 @@ final class EnumeratorTests: NextcloudFileProviderKitTestCase {
21652097 )
21662098
21672099 XCTAssertNil ( readError)
2168- XCTAssertNotNil ( metadatas)
21692100
2170- let postRead = try XCTUnwrap ( Self . dbManager. itemMetadata ( ocId: " lockedFile " ) )
2101+ let postRead = try XCTUnwrap ( Self . dbManager. itemMetadata ( ocId: " lockTokenTestFile " ) )
21712102 XCTAssertEqual (
21722103 postRead. lockToken,
21732104 " local-lock-token-123 " ,
21742105 " lockToken must be preserved across target-depth reads "
21752106 )
2176- XCTAssertTrue ( postRead. downloaded, " downloaded state must be preserved " )
21772107 }
21782108}
0 commit comments