@@ -52,6 +52,35 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le
5252 try ? ParseStorage . shared. deleteAll ( )
5353 }
5454
55+ func testSaveAllCommand( ) throws {
56+ let score = GameScore ( score: 10 )
57+ let score2 = GameScore ( score: 20 )
58+
59+ var scoreOnServer = score
60+ scoreOnServer. objectId = " yarr "
61+ scoreOnServer. createdAt = Date ( )
62+ scoreOnServer. updatedAt = scoreOnServer. createdAt
63+ scoreOnServer. ACL = nil
64+
65+ var scoreOnServer2 = score2
66+ scoreOnServer2. objectId = " yolo "
67+ scoreOnServer2. createdAt = Date ( )
68+ scoreOnServer2. updatedAt = scoreOnServer2. createdAt
69+ scoreOnServer2. ACL = nil
70+
71+ let objects = [ score, score2]
72+ let commands = objects. map { $0. saveCommand ( ) }
73+ let body = BatchCommand ( requests: commands)
74+ // swiftlint:disable:next line_length
75+ let expected = " { \" requests \" :[{ \" path \" : \" \\ /classes \\ /GameScore \" , \" method \" : \" POST \" , \" body \" :{ \" score \" :10}},{ \" path \" : \" \\ /classes \\ /GameScore \" , \" method \" : \" POST \" , \" body \" :{ \" score \" :20}}]} "
76+ let encoded = try ParseCoding . parseEncoder ( )
77+ . encode ( body, collectChildren: false ,
78+ objectsSavedBeforeThisOne: nil ,
79+ filesSavedBeforeThisOne: nil ) . encoded
80+ let decoded = String ( data: encoded, encoding: . utf8)
81+ XCTAssertEqual ( decoded, expected)
82+ }
83+
5584 func testSaveAll( ) { // swiftlint:disable:this function_body_length cyclomatic_complexity
5685 let score = GameScore ( score: 10 )
5786 let score2 = GameScore ( score: 20 )
@@ -235,6 +264,39 @@ class ParseObjectBatchTests: XCTestCase { // swiftlint:disable:this type_body_le
235264 }
236265 }
237266
267+ func testUpdateAllCommand( ) throws {
268+ var score = GameScore ( score: 10 )
269+ var score2 = GameScore ( score: 20 )
270+
271+ score. objectId = " yarr "
272+ score. createdAt = Date ( )
273+ score. updatedAt = Date ( )
274+ score2. objectId = " yolo "
275+ score2. createdAt = Date ( )
276+ score2. updatedAt = Date ( )
277+
278+ let objects = [ score, score2]
279+ let initialCommands = objects. map { $0. saveCommand ( ) }
280+ let commands = initialCommands. compactMap { ( command) -> API . Command < GameScore , GameScore > ? in
281+ let path = ParseConfiguration . mountPath + command. path. urlComponent
282+ guard let body = command. body else {
283+ return nil
284+ }
285+ return API . Command < GameScore , GameScore > ( method: command. method, path: . any( path) ,
286+ body: body, mapper: command. mapper)
287+ }
288+ let body = BatchCommand ( requests: commands)
289+ // swiftlint:disable:next line_length
290+ let expected = " { \" requests \" :[{ \" path \" : \" \\ /1 \\ /classes \\ /GameScore \\ /yarr \" , \" method \" : \" PUT \" , \" body \" :{ \" score \" :10}},{ \" path \" : \" \\ /1 \\ /classes \\ /GameScore \\ /yolo \" , \" method \" : \" PUT \" , \" body \" :{ \" score \" :20}}]} "
291+
292+ let encoded = try ParseCoding . parseEncoder ( )
293+ . encode ( body, collectChildren: false ,
294+ objectsSavedBeforeThisOne: nil ,
295+ filesSavedBeforeThisOne: nil ) . encoded
296+ let decoded = String ( data: encoded, encoding: . utf8)
297+ XCTAssertEqual ( decoded, expected)
298+ }
299+
238300 func testUpdateAll( ) { // swiftlint:disable:this function_body_length cyclomatic_complexity
239301 var score = GameScore ( score: 10 )
240302 score. objectId = " yarr "
0 commit comments