Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support empty response bodies #31

Merged
merged 1 commit into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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