[Bugfix] Communications #7
@ -35,6 +35,12 @@ public struct MakeURLRequestUseCase {
|
|||||||
urlComponents.port = port
|
urlComponents.port = port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !endpoint.parameters.isEmpty {
|
||||||
|
urlComponents.queryItems = endpoint.parameters
|
||||||
|
.map(URLQueryItem.init)
|
||||||
|
.sorted(by: { $0.name < $1.name })
|
||||||
|
}
|
||||||
|
|
||||||
guard let url = urlComponents.url else {
|
guard let url = urlComponents.url else {
|
||||||
throw MakeURLRequestError.urlNotCreated
|
throw MakeURLRequestError.urlNotCreated
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,25 @@ final class MakeURLRequestUseCaseTests: XCTestCase {
|
|||||||
XCTAssertNil(result.httpBody)
|
XCTAssertNil(result.httpBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func test_withEndpoint_initialisedWithParameters() throws {
|
||||||
|
// GIVEN
|
||||||
|
let endpoint = TestEndpoint(parameters: [
|
||||||
|
"someParameter": "someValue",
|
||||||
|
"anotherParameter": nil,
|
||||||
|
"otherParameter": "yetAnotherValue"
|
||||||
|
])
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
let result = try makeURLRequest(endpoint: endpoint)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
XCTAssertNotNil(result)
|
||||||
|
XCTAssertEqual(result.url?.absoluteString, "http://www.something.com/path/to/endpoint?anotherParameter&otherParameter=yetAnotherValue&someParameter=someValue")
|
||||||
|
XCTAssertEqual(result.httpMethod, HTTPRequestMethod.get.rawValue)
|
||||||
|
XCTAssertEqual(result.allHTTPHeaderFields, [:])
|
||||||
|
XCTAssertNil(result.httpBody)
|
||||||
|
}
|
||||||
|
|
||||||
func test_withEndpoint_initialisedWithHeaders() throws {
|
func test_withEndpoint_initialisedWithHeaders() throws {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
let endpoint = TestEndpoint(headers: [
|
let endpoint = TestEndpoint(headers: [
|
||||||
@ -100,23 +119,25 @@ private struct TestEndpoint: Endpoint {
|
|||||||
|
|
||||||
let scheme: String = "http"
|
let scheme: String = "http"
|
||||||
let host: String = "www.something.com"
|
let host: String = "www.something.com"
|
||||||
|
let port: Int?
|
||||||
let path: String = "/path/to/endpoint"
|
let path: String = "/path/to/endpoint"
|
||||||
|
let parameters: Parameters
|
||||||
let method: HTTPRequestMethod = .get
|
let method: HTTPRequestMethod = .get
|
||||||
|
let headers: Headers
|
||||||
var port: Int?
|
let body: Data?
|
||||||
var headers: [String : String]
|
|
||||||
var body: Data?
|
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
|
|
||||||
init(
|
init(
|
||||||
port: Int? = nil,
|
port: Int? = nil,
|
||||||
headers: [String : String] = [:],
|
parameters: Parameters = [:],
|
||||||
|
headers: Headers = [:],
|
||||||
body: Data? = nil
|
body: Data? = nil
|
||||||
) {
|
) {
|
||||||
self.port = port
|
self.port = port
|
||||||
self.body = body
|
self.parameters = parameters
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
|
self.body = body
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user