diff --git a/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Make.swift b/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Make.swift index 1c711b0..53bb7fc 100644 --- a/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Make.swift +++ b/Sources/VaporTestTools/Extensions/Requests/HTTPRequest+Make.swift @@ -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) } diff --git a/Sources/VaporTestTools/Extensions/Testable/Application+Testable.swift b/Sources/VaporTestTools/Extensions/Testable/Application+Testable.swift index b482589..efe8a06 100644 --- a/Sources/VaporTestTools/Extensions/Testable/Application+Testable.swift +++ b/Sources/VaporTestTools/Extensions/Testable/Application+Testable.swift @@ -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) @@ -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 {