@@ -364,13 +364,22 @@ class QueryTests: XCTestCase {
364
364
let insert = try emails. insert ( value)
365
365
let encodedJSON = try JSONEncoder ( ) . encode ( value1)
366
366
let encodedJSONString = String ( data: encodedJSON, encoding: . utf8) !
367
- assertSQL (
367
+
368
+ let expectedSQL =
368
369
"""
369
370
INSERT INTO \" emails \" ( \" int \" , \" string \" , \" bool \" , \" float \" , \" double \" , \" date \" , \" uuid \" , \" optional \" ,
370
371
\" sub \" ) VALUES (1, '2', 1, 3.0, 4.0, '1970-01-01T00:00:00.000', 'E621E1F8-C36C-495A-93FC-0C247A3E6E5F',
371
372
'optional', ' \( encodedJSONString) ')
372
- """ . replacingOccurrences ( of: " \n " , with: " " ) ,
373
- insert
373
+ """ . replacingOccurrences ( of: " \n " , with: " " )
374
+
375
+ // As JSON serialization gives a different result each time, we extract JSON and compare it by deserializing it
376
+ // and keep comparing the query but with the json replaced by the `JSON` string
377
+ let ( expectedQuery, expectedJSON) = extractAndReplace ( expectedSQL, regex: " \\ {.* \\ } " , with: " JSON " )
378
+ let ( actualQuery, actualJSON) = extractAndReplace ( insert. asSQL ( ) , regex: " \\ {.* \\ } " , with: " JSON " )
379
+ XCTAssertEqual ( expectedQuery, actualQuery)
380
+ XCTAssertEqual (
381
+ try JSONDecoder ( ) . decode ( TestCodable . self, from: expectedJSON. data ( using: . utf8) !) ,
382
+ try JSONDecoder ( ) . decode ( TestCodable . self, from: actualJSON. data ( using: . utf8) !)
374
383
)
375
384
}
376
385
#endif
0 commit comments