Skip to content

Commit

Permalink
extractParameter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Jul 13, 2024
1 parent dda1996 commit 08a3c71
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
5 changes: 5 additions & 0 deletions FlyingFox/Tests/HTTPRequest+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ extension HTTPRequest {
headers: headers,
body: body)
}

static func make(_ url: String) -> Self {
let (path, query) = HTTPDecoder.readComponents(from: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
return HTTPRequest.make(path: path, query: query)
}
}
31 changes: 30 additions & 1 deletion FlyingFox/Tests/HTTPRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ final class HTTPRouteTests: XCTestCase {
XCTAssertEqual(HTTPRoute("GET,PUT /fish/*").method, .caseInsensitive("GET"))
}

func testRouteParameters() async {
func testRouteParameters() {
let route = HTTPRoute("GET /mock/:id")
let parameters = route.parameters
XCTAssertEqual(parameters.count, 1)
Expand All @@ -471,6 +471,35 @@ final class HTTPRouteTests: XCTestCase {
XCTAssertEqual(parameters4["fish"], .query(name: "fish", index: "food"))
}

func testRouteParameterValues() {
let route = HTTPRoute("GET /mock/:id?foo=:foo&bar=:bar")

XCTAssertEqual(
route.extractParameters(from: .make("/mock/15?foo=🐟&bar=🍤")),
[
.init(name: "id", value: "15"),
.init(name: "foo", value: "🐟"),
.init(name: "bar", value: "🍤")
]
)

XCTAssertEqual(
route.extractParameters(from: .make("/mock/99?bar=🐠&foo=🍟")),
[
.init(name: "id", value: "99"),
.init(name: "foo", value: "🍟"),
.init(name: "bar", value: "🐠")
]
)

XCTAssertEqual(
route.extractParameters(from: .make("/mock?bar=🐠")),
[
.init(name: "bar", value: "🐠")
]
)
}

#if compiler(>=5.9)
func testPathParameters() {
// given
Expand Down
8 changes: 0 additions & 8 deletions FlyingFox/Tests/Handlers/RoutedHTTPHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ private extension HTTPRoute {
}
}

private extension HTTPRequest {

static func make(_ url: String) -> Self {
let (path, query) = HTTPDecoder.readComponents(from: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
return HTTPRequest.make(path: path, query: query)
}
}

private extension HTTPResponse {

var bodyString: String? {
Expand Down

0 comments on commit 08a3c71

Please sign in to comment.