@@ -53,7 +53,10 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
53
53
amzDate: date
54
54
)
55
55
56
- XCTAssertEqual ( toJson ( iamAuth) ? . shrink ( ) , """
56
+ // Convert to JSON and then parse it back into a dictionary for comparison
57
+ let iamAuthJson = toJson ( iamAuth) ? . shrink ( )
58
+
59
+ let expectedJsonString = """
57
60
{
58
61
" accept " : " application \\ /json, text \\ /javascript " ,
59
62
" Authorization " : " \( token) " ,
@@ -63,7 +66,24 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
63
66
" x-amz-date " : " \( date) " ,
64
67
" X-Amz-Security-Token " : " \( securityToken) "
65
68
}
66
- """ . shrink ( ) )
69
+ """ . shrink ( )
70
+
71
+ // Convert both JSON strings to dictionaries for comparison
72
+ let iamAuthDict = convertToDictionary ( text: iamAuthJson)
73
+ let expectedDict = convertToDictionary ( text: expectedJsonString)
74
+
75
+ // Assert that the dictionaries are equal using the custom method
76
+ XCTAssertTrue ( areDictionariesEqual ( iamAuthDict, expectedDict) )
77
+ }
78
+
79
+ private func convertToDictionary( text: String ? ) -> [ String : Any ] ? {
80
+ guard let data = text? . data ( using: . utf8) else { return nil }
81
+ return try ? JSONSerialization . jsonObject ( with: data, options: [ ] ) as? [ String : Any ]
82
+ }
83
+
84
+ private func areDictionariesEqual( _ lhs: [ String : Any ] ? , _ rhs: [ String : Any ] ? ) -> Bool {
85
+ guard let lhs = lhs, let rhs = rhs else { return false }
86
+ return NSDictionary ( dictionary: lhs) . isEqual ( to: rhs)
67
87
}
68
88
69
89
func testAppSyncRealTimeRequestAuth_encodeStartRequestWithCognitoAuth( ) {
@@ -124,8 +144,9 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
124
144
let request = AppSyncRealTimeRequest . start (
125
145
. init( id: id, data: data, auth: . iam( iamAuth) )
126
146
)
127
- let requestJson = toJson ( request)
128
- XCTAssertEqual ( requestJson? . shrink ( ) , """
147
+ let requestJson = toJson ( request) ? . shrink ( )
148
+
149
+ let expectedJsonString = """
129
150
{
130
151
" id " : " \( id) " ,
131
152
" payload " : {
@@ -144,7 +165,14 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
144
165
},
145
166
" type " : " start "
146
167
}
147
- """ . shrink ( ) )
168
+ """ . shrink ( )
169
+
170
+ // Convert both JSON strings to dictionaries for comparison
171
+ let requestDict = convertToDictionary ( text: requestJson)
172
+ let expectedDict = convertToDictionary ( text: expectedJsonString)
173
+
174
+ // Assert that the dictionaries are equal using the custom method
175
+ XCTAssertTrue ( areDictionariesEqual ( requestDict, expectedDict) )
148
176
}
149
177
150
178
private func toJson( _ value: Encodable ) -> String ? {
0 commit comments