Skip to content

Commit

Permalink
fix(test): replace string comparison of encoded body with back parser (
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime authored Aug 29, 2024
1 parent 4e90307 commit dfc20c7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Tests/PostieTests/RequestBodyCodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ class RequestBodyCodingTests: XCTestCase {
XCTFail("Failed to encode: " + error.localizedDescription)
return
}
XCTAssertEqual(encoded.httpBody, #"{"someOtherValue":"Bar","someValue":123}"#.data(using: .utf8)!)
// The order of the encoded fields is ambiguous, therefore we need to parse the json and compare it
guard let encodedHttpBody = encoded.httpBody else {
XCTFail("Encoded HTTP body should exst")
return
}
let parsedJsonObject = try? JSONSerialization.jsonObject(with: encodedHttpBody, options: [])
XCTAssertEqual((parsedJsonObject as? [String: Any])?["someValue"] as? Int, 123)
XCTAssertEqual((parsedJsonObject as? [String: Any])?["someOtherValue"] as? String, "Bar")
XCTAssertEqual(encoded.value(forHTTPHeaderField: "Content-Type"), "application/json")
}

Expand Down

0 comments on commit dfc20c7

Please sign in to comment.