Skip to content

Commit

Permalink
returning calculated request with response
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Mar 7, 2018
1 parent ceb158a commit 95e6793
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,27 @@ extension TestableProperty where TestableType == HTTPRequest {
return req
}

public static func response(get uri: URI, headers: [String: String]? = nil, with app: Application) -> Response {
public static func response(get uri: URI, headers: [String: String]? = nil, with app: Application) -> TestResponse {
let req = request(method: .get, uri: uri, headers: headers)
return app.testable.response(to: req)
}

public static func response(put uri: URI, data: Data? = nil, headers: [String: String]? = nil, with app: Application) -> Response {
public static func response(put uri: URI, data: Data? = nil, headers: [String: String]? = nil, with app: Application) -> TestResponse {
let req = request(method: .put, uri: uri, data: data, headers: headers)
return app.testable.response(to: req)
}

public static func response(post uri: URI, data: Data? = nil, headers: [String: String]? = nil, with app: Application) -> Response {
public static func response(post uri: URI, data: Data? = nil, headers: [String: String]? = nil, with app: Application) -> TestResponse {
let req = request(method: .post, uri: uri, data: data, headers: headers)
return app.testable.response(to: req)
}

public static func response(patch uri: URI, data: Data? = nil, headers: [String: String]? = nil, with app: Application) -> Response {
public static func response(patch uri: URI, data: Data? = nil, headers: [String: String]? = nil, with app: Application) -> TestResponse {
let req = request(method: .patch, uri: uri, data: data, headers: headers)
return app.testable.response(to: req)
}

public static func response(delete uri: URI, headers: [String: String]? = nil, with app: Application) -> Response {
public static func response(delete uri: URI, headers: [String: String]? = nil, with app: Application) -> TestResponse {
let req = request(method: .delete, uri: uri, headers: headers)
return app.testable.response(to: req)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Vapor
import Routing


public typealias TestResponse = (response: Response, request: Request)


extension TestableProperty where TestableType: Application {

public typealias AppConfigClosure = ((_ config: inout Config, _ env: inout Vapor.Environment, _ services: inout Services) -> Void)
Expand All @@ -29,16 +32,16 @@ extension TestableProperty where TestableType: Application {
return app
}

public func response(to request: HTTPRequest) -> Response {
public func response(to request: HTTPRequest) -> TestResponse {
let responder = try! element.make(Responder.self)
let wrappedRequest = Request(http: request, using: element)
return try! responder.respond(to: wrappedRequest).await(on: element)
return try! (response: responder.respond(to: wrappedRequest).await(on: element), request: wrappedRequest)
}

public func response(throwingTo request: HTTPRequest) throws -> Response {
public func response(throwingTo request: HTTPRequest) throws -> TestResponse {
let responder = try element.make(Responder.self)
let wrappedRequest = Request(http: request, using: element)
return try responder.respond(to: wrappedRequest).await(on: element)
return try (response: responder.respond(to: wrappedRequest).await(on: element), request: wrappedRequest)
}

public func fakeRequest() -> Request {
Expand Down

0 comments on commit 95e6793

Please sign in to comment.