diff --git a/Sources/CoreDataRepository/CoreDataRepository+Batch.swift b/Sources/CoreDataRepository/CoreDataRepository+Batch.swift index 20c7aa9..59f819b 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Batch.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Batch.swift @@ -82,10 +82,20 @@ extension CoreDataRepository { /// - urls: [URL] /// - Returns /// - (success: [Model, failed: [Model]) + @available(*, deprecated, message: "This method has an unused parameter for transactionAuthor.") public func read( urls: [URL], transactionAuthor _: String? = nil ) async -> (success: [Model], failed: [URL]) { + await read(urls: urls) + } + + /// Batch update objects in CoreData + /// - Parameters + /// - urls: [URL] + /// - Returns + /// - (success: [Model, failed: [Model]) + public func read(urls: [URL]) async -> (success: [Model], failed: [URL]) { var successes = [Model]() var failures = [URL]() await withTaskGroup(of: _Result.self, body: { [weak self] group in diff --git a/Tests/CoreDataRepositoryTests/BatchRepositoryTests.swift b/Tests/CoreDataRepositoryTests/BatchRepositoryTests.swift index 6159129..ad5124e 100644 --- a/Tests/CoreDataRepositoryTests/BatchRepositoryTests.swift +++ b/Tests/CoreDataRepositoryTests/BatchRepositoryTests.swift @@ -142,6 +142,28 @@ final class BatchRepositoryTests: CoreDataXCTestCase { try verify(transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp) } + func testDeprecatedReadSuccess() async throws { + let fetchRequest = NSFetchRequest(entityName: "RepoMovie") + var movies = [Movie]() + try await repositoryContext().perform { + let count = try self.repositoryContext().count(for: fetchRequest) + XCTAssertEqual(count, 0, "Count of objects in CoreData should be zero at the start of each test.") + + let repoMovies = try self.movies + .map(self.mapDictToRepoMovie(_:)) + try self.repositoryContext().save() + movies = repoMovies.map(\.asUnmanaged) + } + + let result: (success: [Movie], failed: [URL]) = try await repository() + .read(urls: movies.compactMap(\.url), transactionAuthor: "Unused") + + XCTAssertEqual(result.success.count, movies.count) + XCTAssertEqual(result.failed.count, 0) + + XCTAssertEqual(Set(movies), Set(result.success)) + } + func testReadSuccess() async throws { let fetchRequest = NSFetchRequest(entityName: "RepoMovie") var movies = [Movie]()