Skip to content

Commit

Permalink
Support empty response bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
diogoguimaraes committed Feb 22, 2016
1 parent 10d0f98 commit 916f8d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Source/Client/UpholdRestAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ public class UpholdRestAdapter {
return
}

guard let _ = response.text else {
if let body = response.text where !body.isEmpty {
reject(LogicError(code: nil, message: "Response body should be empty."))
} else {
fulfill(response)

return
}

reject(LogicError(code: nil, message: "Response body should be empty."))
}, onError: { (error: NSError) -> Void in
reject(error)
})
Expand Down
16 changes: 16 additions & 0 deletions Tests/Integration/Client/UpholdRestAdapterTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ class UpholdRestAdapterTest: UpholdTestCase {
wait()
}

func testBuildEmptyResponseWithBodyShouldReturnFulfilledPromise() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")
let mockRequest = MockRequest(body: "", code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<Response> = UpholdRestAdapter().buildEmptyResponse(request)

promise.then { (response: Response) -> () in
XCTAssertEqual(response.basicStatus, Response.BasicResponseType.OK, "Failed: Wrong response basic status code.")
XCTAssertEqual(response.text, "", "Failed: Wrong response body.")

expectation.fulfill()
}

wait()
}

func testBuildEmptyResponseShouldReturnLogicError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")
let mockRequest = MockRequest(body: "foobar", code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
Expand Down

0 comments on commit 916f8d9

Please sign in to comment.