@@ -57,8 +57,12 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
5757 XCTAssertEqual ( count, 0 , " Count of objects in CoreData should be zero at the start of each test. " )
5858 }
5959
60+ let historyTimeStamp = Date ( )
61+ let transactionAuthor : String = #function
62+
6063 let request = try NSBatchInsertRequest ( entityName: XCTUnwrap ( RepoMovie . entity ( ) . name) , objects: movies)
61- let result : Result < NSBatchInsertResult , CoreDataRepositoryError > = try await repository ( ) . insert ( request)
64+ let result : Result < NSBatchInsertResult , CoreDataRepositoryError > = try await repository ( )
65+ . insert ( request, transactionAuthor: transactionAuthor)
6266
6367 switch result {
6468 case . success:
@@ -75,6 +79,8 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
7579 " Inserted titles should match expectation "
7680 )
7781 }
82+
83+ try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
7884 }
7985
8086 func testInsertFailure( ) async throws {
@@ -110,8 +116,12 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
110116 XCTAssertEqual ( count, 0 , " Count of objects in CoreData should be zero at the start of each test. " )
111117 }
112118
119+ let historyTimeStamp = Date ( )
120+ let transactionAuthor : String = #function
121+
113122 let newMovies = try movies. map ( mapDictToMovie ( _: ) )
114- let result : ( success: [ Movie ] , failed: [ Movie ] ) = try await repository ( ) . create ( newMovies)
123+ let result : ( success: [ Movie ] , failed: [ Movie ] ) = try await repository ( )
124+ . create ( newMovies, transactionAuthor: transactionAuthor)
115125
116126 XCTAssertEqual ( result. success. count, newMovies. count)
117127 XCTAssertEqual ( result. failed. count, 0 )
@@ -128,6 +138,8 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
128138 " Inserted titles should match expectation "
129139 )
130140 }
141+
142+ try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
131143 }
132144
133145 func testReadSuccess( ) async throws {
@@ -167,7 +179,11 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
167179 request. predicate = predicate
168180 request. propertiesToUpdate = [ " title " : " Updated! " , " boxOffice " : 1 ]
169181
170- let _: Result < NSBatchUpdateResult , CoreDataRepositoryError > = try await repository ( ) . update ( request)
182+ let historyTimeStamp = Date ( )
183+ let transactionAuthor : String = #function
184+
185+ let _: Result < NSBatchUpdateResult , CoreDataRepositoryError > = try await repository ( )
186+ . update ( request, transactionAuthor: transactionAuthor)
171187
172188 try await repositoryContext ( ) . perform {
173189 let data = try self . repositoryContext ( ) . fetch ( fetchRequest)
@@ -177,6 +193,7 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
177193 " Updated titles should match request "
178194 )
179195 }
196+ try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
180197 }
181198
182199 func testAltUpdateSuccess( ) async throws {
@@ -196,12 +213,18 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
196213 let newTitles = [ " ZA " , " ZB " , " ZC " , " ZD " , " ZE " ]
197214 newTitles. enumerated ( ) . forEach { index, title in editedMovies [ index] . title = title }
198215
199- let result : ( success: [ Movie ] , failed: [ Movie ] ) = try await repository ( ) . update ( editedMovies)
216+ let historyTimeStamp = Date ( )
217+ let transactionAuthor : String = #function
218+
219+ let result : ( success: [ Movie ] , failed: [ Movie ] ) = try await repository ( )
220+ . update ( editedMovies, transactionAuthor: transactionAuthor)
200221
201222 XCTAssertEqual ( result. success. count, movies. count)
202223 XCTAssertEqual ( result. failed. count, 0 )
203224
204225 XCTAssertEqual ( Set ( editedMovies) , Set ( result. success) )
226+
227+ try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
205228 }
206229
207230 func testDeleteSuccess( ) async throws {
@@ -221,12 +244,17 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
221244 . entity ( ) . name
222245 ) ) )
223246
224- let _: Result < NSBatchDeleteResult , CoreDataRepositoryError > = try await repository ( ) . delete ( request)
247+ let historyTimeStamp = Date ( )
248+ let transactionAuthor : String = #function
249+
250+ let _: Result < NSBatchDeleteResult , CoreDataRepositoryError > = try await repository ( )
251+ . delete ( request, transactionAuthor: transactionAuthor)
225252
226253 try await repositoryContext ( ) . perform {
227254 let data = try self . repositoryContext ( ) . fetch ( fetchRequest)
228255 XCTAssertEqual ( data. map { $0. title ?? " " } . sorted ( ) , [ ] , " There should be no remaining values. " )
229256 }
257+ try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
230258 }
231259
232260 func testAltDeleteSuccess( ) async throws {
@@ -242,7 +270,11 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
242270 movies = repoMovies. map ( \. asUnmanaged)
243271 }
244272
245- let result : ( success: [ URL ] , failed: [ URL ] ) = try await repository ( ) . delete ( urls: movies. compactMap ( \. url) )
273+ let historyTimeStamp = Date ( )
274+ let transactionAuthor : String = #function
275+
276+ let result : ( success: [ URL ] , failed: [ URL ] ) = try await repository ( )
277+ . delete ( urls: movies. compactMap ( \. url) , transactionAuthor: transactionAuthor)
246278
247279 XCTAssertEqual ( result. success. count, movies. count)
248280 XCTAssertEqual ( result. failed. count, 0 )
@@ -251,5 +283,6 @@ final class BatchRepositoryTests: CoreDataXCTestCase {
251283 let data = try self . repositoryContext ( ) . fetch ( fetchRequest)
252284 XCTAssertEqual ( data. map { $0. title ?? " " } . sorted ( ) , [ ] , " There should be no remaining values. " )
253285 }
286+ try verify ( transactionAuthor: transactionAuthor, timeStamp: historyTimeStamp)
254287 }
255288}
0 commit comments