From 45a947addf9da7b75d23b0ddb99f718f5d15b3e9 Mon Sep 17 00:00:00 2001 From: Jaanus Kase Date: Tue, 6 Aug 2024 14:53:45 +0300 Subject: [PATCH] Removed MockCKRecord --- Targets/Canopy/Tests/MockObjectTests.swift | 6 -- .../Sources/MockCKRecord/MockCKRecord.swift | 95 ------------------- 2 files changed, 101 deletions(-) delete mode 100644 Targets/CanopyTestTools/Sources/MockCKRecord/MockCKRecord.swift diff --git a/Targets/Canopy/Tests/MockObjectTests.swift b/Targets/Canopy/Tests/MockObjectTests.swift index 4a4f4a9..bdd096c 100644 --- a/Targets/Canopy/Tests/MockObjectTests.swift +++ b/Targets/Canopy/Tests/MockObjectTests.swift @@ -16,10 +16,4 @@ final class MockObjectTests: XCTestCase { let share = CKShare.mock_owned_by_current_user XCTAssertEqual(share.participants.count, 3) } - - func test_mock_record_change_tag() { - let mockRecord = MockCKRecord(recordType: "MyType") - mockRecord[MockCKRecord.testingRecordChangeTag] = "myTag" - XCTAssertEqual(mockRecord.recordChangeTag, "myTag") - } } diff --git a/Targets/CanopyTestTools/Sources/MockCKRecord/MockCKRecord.swift b/Targets/CanopyTestTools/Sources/MockCKRecord/MockCKRecord.swift deleted file mode 100644 index b454bee..0000000 --- a/Targets/CanopyTestTools/Sources/MockCKRecord/MockCKRecord.swift +++ /dev/null @@ -1,95 +0,0 @@ -import CloudKit -import Foundation - -public protocol CKRecordMocking { - var recordID: CKRecord.ID { get } -} - -/// Mock version of CKRecord, suitable for using in tests. -/// -/// This behaves similarly to CKRecord, but lets you override some fields -/// that are set by CloudKit on the server side: most importantly, -/// creator user record name, creation and modification times, and change tag. -/// This is useful for testing where you need to test with the content of these fields -/// present, but are constructing the records locally as test fixtures -/// instead of obtaining them from the server. -public class MockCKRecord: CKRecord, CKRecordMocking { - public static let testingCreatorUserRecordNameKey = "testingCreatorUserRecordNameKey" - public static let testingCreatedAtKey = "testingCreatedAtKey" - public static let testingModifiedAtKey = "testingModifiedAtKey" - public static let testingRecordChangeTag = "testingRecordChangeTag" - - override public var creatorUserRecordID: CKRecord.ID? { - guard let testing = self[MockCKRecord.testingCreatorUserRecordNameKey] as? String else { - return nil - } - - return CKRecord.ID(recordName: testing) - } - - override public var creationDate: Date? { - guard let testing = self[MockCKRecord.testingCreatedAtKey] as? Date else { - return nil - } - return testing - } - - override public var modificationDate: Date? { - guard let testing = self[MockCKRecord.testingModifiedAtKey] as? Date else { - return nil - } - return testing - } - - override public var recordChangeTag: String? { - guard let testing = self[MockCKRecord.testingRecordChangeTag] as? String else { - return nil - } - return testing - } - - override public class var supportsSecureCoding: Bool { - true - } - - public static func mock( - recordType: String, - recordID: CKRecord.ID, - parentRecordID: CKRecord.ID? = nil, - creatorUserRecordName: String = UUID().uuidString, - recordChangeTag: String? = nil, - properties: [String: CKRecordValueProtocol?] - ) -> MockCKRecord { - let record = MockCKRecord(recordType: recordType, recordID: recordID) - - if let parentID = parentRecordID { - record.parent = CKRecord.Reference(recordID: parentID, action: .none) - } - - record[testingCreatorUserRecordNameKey] = creatorUserRecordName - record[testingRecordChangeTag] = recordChangeTag - - for (key, value) in properties { - record[key] = value - } - - return record - } - - public static func mock(record: CKRecord) -> MockCKRecord { - let mock = MockCKRecord(recordType: record.recordType, recordID: record.recordID) - - if let parentID = record.parent?.recordID { - mock.parent = CKRecord.Reference(recordID: parentID, action: .none) - } - - mock[testingCreatorUserRecordNameKey] = record.creatorUserRecordID?.recordName - mock[testingRecordChangeTag] = record.recordChangeTag - - for key in mock.allKeys() { - mock[key] = record[key] - } - - return mock - } -}