Skip to content

Commit

Permalink
Added test around posting unicode parameters with URL encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Sep 6, 2015
1 parent 21040ab commit ba6d3dd
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Tests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,52 @@ class RequestResponseTestCase: BaseTestCase {
XCTFail("last item in bytesValues and progressValues should not be nil")
}
}

func testThatPOSTRequestWithUnicodeParametersEncodesAndTransmitsParametersAsExpected() {
// Given
let URLString = "https://httpbin.org/post"
let parameters = [
"french": "français",
"japanese": "日本語",
"arabic": "العربية",
"emoji": "😃"
]

let expectation = expectationWithDescription("request should succeed")

var request: NSURLRequest?
var response: NSHTTPURLResponse?
var result: Result<AnyObject>?

// When
Alamofire.request(.POST, URLString, parameters: parameters)
.responseJSON { responseRequest, responseResponse, responseResult in
request = responseRequest
response = responseResponse
result = responseResult

expectation.fulfill()
}

waitForExpectationsWithTimeout(defaultTimeout, handler: nil)

// Then
XCTAssertNotNil(request, "request should not be nil")
XCTAssertNotNil(response, "response should not be nil")
XCTAssertNotNil(result, "result should be nil")

if let
JSON = result?.value as? [String: AnyObject],
form = JSON["form"] as? [String: String]
{
XCTAssertEqual(form["french"], parameters["french"], "french parameter value should match form value")
XCTAssertEqual(form["japanese"], parameters["japanese"], "japanese parameter value should match form value")
XCTAssertEqual(form["arabic"], parameters["arabic"], "arabic parameter value should match form value")
XCTAssertEqual(form["emoji"], parameters["emoji"], "emoji parameter value should match form value")
} else {
XCTFail("headers parameter in JSON should not be nil")
}
}
}

// MARK: -
Expand Down

0 comments on commit ba6d3dd

Please sign in to comment.