@@ -253,4 +253,54 @@ final class ItemPropertyTests: XCTestCase {
253253 )
254254 XCTAssertFalse ( item. capabilities. contains ( . allowsTrashing) )
255255 }
256+
257+ func testItemShared( ) {
258+ var sharedMetadata =
259+ SendableItemMetadata ( ocId: " test-id " , fileName: " test.txt " , account: Self . account)
260+ sharedMetadata. shareType = [ ShareType . publicLink. rawValue]
261+ sharedMetadata. ownerId = Self . account. id
262+ sharedMetadata. ownerDisplayName = " Mr. Tester Testarino "
263+ let sharedItem = Item (
264+ metadata: sharedMetadata,
265+ parentItemIdentifier: . rootContainer,
266+ account: Self . account,
267+ remoteInterface: MockRemoteInterface ( ) ,
268+ dbManager: Self . dbManager
269+ )
270+ XCTAssertTrue ( sharedItem. isShared)
271+ XCTAssertTrue ( sharedItem. isSharedByCurrentUser)
272+ XCTAssertNil ( sharedItem. ownerNameComponents) // Should be nil if it is shared by us
273+
274+ var sharedByOtherMetadata = sharedMetadata
275+ sharedByOtherMetadata. ownerId = " claucambra "
276+ sharedByOtherMetadata. ownerDisplayName = " Claudio Cambra "
277+ let sharedByOtherTime = Item (
278+ metadata: sharedByOtherMetadata,
279+ parentItemIdentifier: . rootContainer,
280+ account: Self . account,
281+ remoteInterface: MockRemoteInterface ( ) ,
282+ dbManager: Self . dbManager
283+ )
284+ XCTAssertTrue ( sharedByOtherTime. isShared)
285+ XCTAssertFalse ( sharedByOtherTime. isSharedByCurrentUser)
286+ XCTAssertNotNil ( sharedByOtherTime. ownerNameComponents)
287+ XCTAssertEqual ( sharedByOtherTime. ownerNameComponents? . givenName, " Claudio " )
288+ XCTAssertEqual ( sharedByOtherTime. ownerNameComponents? . familyName, " Cambra " )
289+
290+ var notSharedMetadata =
291+ SendableItemMetadata ( ocId: " test-id " , fileName: " test.txt " , account: Self . account)
292+ notSharedMetadata. ownerId = Self . account. id
293+ notSharedMetadata. ownerDisplayName = " Mr. Tester Testarino "
294+ let notSharedItem = Item (
295+ metadata: notSharedMetadata,
296+ parentItemIdentifier: . rootContainer,
297+ account: Self . account,
298+ remoteInterface: MockRemoteInterface ( ) ,
299+ dbManager: Self . dbManager
300+ )
301+ debugPrint ( notSharedMetadata. shareType)
302+ XCTAssertFalse ( notSharedItem. isShared)
303+ XCTAssertFalse ( notSharedItem. isSharedByCurrentUser)
304+ XCTAssertNil ( notSharedItem. ownerNameComponents)
305+ }
256306}
0 commit comments