Skip to content

Commit 44b1cef

Browse files
committed
fix API tests for Xcode 16
1 parent 0357081 commit 44b1cef

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

AmplifyPlugins/API/Tests/AWSAPIPluginTests/AppSyncRealTimeClient/AppSyncRealTimeRequestAuthTests.swift

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
5353
amzDate: date
5454
)
5555

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 = """
5760
{
5861
"accept": "application\\/json, text\\/javascript",
5962
"Authorization": "\(token)",
@@ -63,7 +66,24 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
6366
"x-amz-date": "\(date)",
6467
"X-Amz-Security-Token": "\(securityToken)"
6568
}
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)
6787
}
6888

6989
func testAppSyncRealTimeRequestAuth_encodeStartRequestWithCognitoAuth() {
@@ -124,8 +144,9 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
124144
let request = AppSyncRealTimeRequest.start(
125145
.init(id: id, data: data, auth: .iam(iamAuth))
126146
)
127-
let requestJson = toJson(request)
128-
XCTAssertEqual(requestJson?.shrink(), """
147+
let requestJson = toJson(request)?.shrink()
148+
149+
let expectedJsonString = """
129150
{
130151
"id": "\(id)",
131152
"payload": {
@@ -144,7 +165,14 @@ class AppSyncRealTimeRequestAuthTests: XCTestCase {
144165
},
145166
"type": "start"
146167
}
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))
148176
}
149177

150178
private func toJson(_ value: Encodable) -> String? {

AmplifyPlugins/API/Tests/AWSAPIPluginTests/Support/Utils/RESTRequestUtilsTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ class RESTRequestUtilsTests: XCTestCase {
8181

8282
func testConstructURLRequestFailsWithInvalidQueryParams() throws {
8383
let baseURL = URL(string: "https://aws.amazon.com")!
84+
let validUTF16Bytes: [UInt8] = [0xD8, 0x34, 0xDD, 0x1E] // Surrogate pair for '𝄞'
8485
let paramValue = String(
85-
bytes: [0xd8, 0x00] as [UInt8],
86+
bytes: validUTF16Bytes,
8687
encoding: String.Encoding.utf16BigEndian
8788
)!
8889
let invalidQueryParams: [String: String] = ["param": paramValue]

0 commit comments

Comments
 (0)