Skip to content

Commit b4197bc

Browse files
committed
Fix CRUD testCreateFailure so that setup is more consistent with other tests
batch-create-fails-with-parent-context-rollback
1 parent 1af4dac commit b4197bc

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

Tests/CoreDataRepositoryTests/CRUDRepositoryTests.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,22 @@ final class CRUDRepositoryTests: CoreDataXCTestCase {
3535
let historyTimeStamp = Date()
3636
let transactionAuthor: String = #function
3737
let movie = Movie(id: UUID(), title: "Create Success", releaseDate: Date(), boxOffice: 100)
38-
let result1: Result<Movie, CoreDataError> = try await repository()
39-
.create(movie, transactionAuthor: transactionAuthor)
40-
guard case let .success(result1Movie) = result1 else {
41-
XCTFail("Not expecting a failed result")
42-
return
38+
var existingMovie = try await repositoryContext().perform(schedule: .immediate) {
39+
let object = try ManagedMovie(context: self.repositoryContext())
40+
try movie.updating(managed: object)
41+
try self.repositoryContext().save()
42+
return try Movie(managed: object)
4343
}
44-
var tempResultMovie = result1Movie
44+
var tempResultMovie = existingMovie
4545
XCTAssertNotNil(tempResultMovie.url)
4646
tempResultMovie.url = nil
4747
XCTAssertNoDifference(tempResultMovie, movie)
4848

49-
try await verify(result1Movie)
50-
try verify(transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
49+
try await verify(existingMovie)
5150

52-
let result2: Result<Movie, CoreDataError> = try await repository()
51+
let result: Result<Movie, CoreDataError> = try await repository()
5352
.create(movie, transactionAuthor: transactionAuthor)
54-
guard case .failure = result2 else {
53+
guard case .failure = result else {
5554
XCTFail("Expecting a failed result")
5655
return
5756
}

0 commit comments

Comments
 (0)