Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/CoreDataRepository/CoreDataRepository+Batch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Model: UnmanagedModel>(
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<Model: UnmanagedModel>(urls: [URL]) async -> (success: [Model], failed: [URL]) {
var successes = [Model]()
var failures = [URL]()
await withTaskGroup(of: _Result<Model, URL>.self, body: { [weak self] group in
Expand Down
22 changes: 22 additions & 0 deletions Tests/CoreDataRepositoryTests/BatchRepositoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
try verify(transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
}

func testDeprecatedReadSuccess() async throws {
let fetchRequest = NSFetchRequest<RepoMovie>(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<RepoMovie>(entityName: "RepoMovie")
var movies = [Movie]()
Expand Down