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