|
1349 | 1349 | } |
1350 | 1350 | } |
1351 | 1351 |
|
| 1352 | + /// Deleting a root shared record that is not owned by current user should only delete |
| 1353 | + /// the CKShare but not the actual records, including associated records. |
| 1354 | + @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
| 1355 | + @Test func deleteRootSharedRecord_CurrentUserNotOwner_DoNotCascade() async throws { |
| 1356 | + let externalZone = CKRecordZone( |
| 1357 | + zoneID: CKRecordZone.ID( |
| 1358 | + zoneName: "external.zone", |
| 1359 | + ownerName: "external.owner" |
| 1360 | + ) |
| 1361 | + ) |
| 1362 | + try await syncEngine.modifyRecordZones(scope: .shared, saving: [externalZone]).notify() |
| 1363 | + |
| 1364 | + let modelARecord = CKRecord( |
| 1365 | + recordType: ModelA.tableName, |
| 1366 | + recordID: ModelA.recordID(for: 1, zoneID: externalZone.zoneID) |
| 1367 | + ) |
| 1368 | + modelARecord.setValue(42, forKey: "count", at: now) |
| 1369 | + |
| 1370 | + let share = CKShare( |
| 1371 | + rootRecord: modelARecord, |
| 1372 | + shareID: CKRecord.ID( |
| 1373 | + recordName: "share-\(modelARecord.recordID.recordName)", |
| 1374 | + zoneID: modelARecord.recordID.zoneID |
| 1375 | + ) |
| 1376 | + ) |
| 1377 | + |
| 1378 | + try await syncEngine |
| 1379 | + .acceptShare( |
| 1380 | + metadata: ShareMetadata( |
| 1381 | + containerIdentifier: container.containerIdentifier!, |
| 1382 | + hierarchicalRootRecordID: modelARecord.recordID, |
| 1383 | + rootRecord: modelARecord, |
| 1384 | + share: share |
| 1385 | + ) |
| 1386 | + ) |
| 1387 | + |
| 1388 | + try await userDatabase.userWrite { db in |
| 1389 | + try db.seed { |
| 1390 | + ModelB(id: 1, isOn: true, modelAID: 1) |
| 1391 | + ModelC(id: 1, title: "Hello world!", modelBID: 1) |
| 1392 | + } |
| 1393 | + } |
| 1394 | + |
| 1395 | + try await syncEngine.processPendingRecordZoneChanges(scope: .shared) |
| 1396 | + |
| 1397 | + try await userDatabase.userWrite { db in |
| 1398 | + try ModelA.find(1).delete().execute(db) |
| 1399 | + } |
| 1400 | + |
| 1401 | + try await syncEngine.processPendingRecordZoneChanges(scope: .shared) |
| 1402 | + |
| 1403 | + assertQuery(Reminder.all, database: userDatabase.database) { |
| 1404 | + """ |
| 1405 | + (No results) |
| 1406 | + """ |
| 1407 | + } |
| 1408 | + assertQuery(RemindersList.all, database: userDatabase.database) { |
| 1409 | + """ |
| 1410 | + (No results) |
| 1411 | + """ |
| 1412 | + } |
| 1413 | + assertQuery(SyncMetadata.all, database: syncEngine.metadatabase) { |
| 1414 | + """ |
| 1415 | + (No results) |
| 1416 | + """ |
| 1417 | + } |
| 1418 | + assertInlineSnapshot(of: container, as: .customDump) { |
| 1419 | + """ |
| 1420 | + MockCloudContainer( |
| 1421 | + privateCloudDatabase: MockCloudDatabase( |
| 1422 | + databaseScope: .private, |
| 1423 | + storage: [] |
| 1424 | + ), |
| 1425 | + sharedCloudDatabase: MockCloudDatabase( |
| 1426 | + databaseScope: .shared, |
| 1427 | + storage: [ |
| 1428 | + [0]: CKRecord( |
| 1429 | + recordID: CKRecord.ID(1:modelAs/external.zone/external.owner), |
| 1430 | + recordType: "modelAs", |
| 1431 | + parent: nil, |
| 1432 | + share: CKReference(recordID: CKRecord.ID(share-1:modelAs/external.zone/external.owner)), |
| 1433 | + count: 42 |
| 1434 | + ), |
| 1435 | + [1]: CKRecord( |
| 1436 | + recordID: CKRecord.ID(1:modelBs/external.zone/external.owner), |
| 1437 | + recordType: "modelBs", |
| 1438 | + parent: CKReference(recordID: CKRecord.ID(1:modelAs/external.zone/external.owner)), |
| 1439 | + share: nil, |
| 1440 | + id: 1, |
| 1441 | + isOn: 1, |
| 1442 | + modelAID: 1 |
| 1443 | + ), |
| 1444 | + [2]: CKRecord( |
| 1445 | + recordID: CKRecord.ID(1:modelCs/external.zone/external.owner), |
| 1446 | + recordType: "modelCs", |
| 1447 | + parent: CKReference(recordID: CKRecord.ID(1:modelBs/external.zone/external.owner)), |
| 1448 | + share: nil, |
| 1449 | + id: 1, |
| 1450 | + modelBID: 1, |
| 1451 | + title: "Hello world!" |
| 1452 | + ) |
| 1453 | + ] |
| 1454 | + ) |
| 1455 | + ) |
| 1456 | + """ |
| 1457 | + } |
| 1458 | + } |
| 1459 | + |
1352 | 1460 | /// Syncing deletion of a root shared record that is not owned by current user should delete |
1353 | 1461 | /// entire zone. |
1354 | 1462 | @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) |
|
0 commit comments