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

Add XCTHTTPClient #3161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add XCTHTTPClient #3161

wants to merge 1 commit into from

Conversation

AFutureD
Copy link

This PR allow user to tests Services or Method without perform actual requests.

Here is an example.

final class AppleTests: XCTestCase {
    
    var client = XCTHTTPClient(eventLoop: nil)
   
    func testSomething() async throws {
        
        var resp: ClientResponse = .init(status: .ok)
        try resp.content.encode(content, as: HTTPMediaType.json)
        
        client.mock(
            request: .init(method: .POST, url: .init(string: AppleApi.ValidationTokenRequest.method)),
            response: resp
        )
        
        let service = Service(signers: signers, client: client , properties: prop, log: log)
        
        let req = AppleApi.ValidationTokenRequest.init("...")
        let result = try await service.validateToken(request: req)
        
        guard case let .success(received) = result else {
            XCTFail()
            return
        }
        
        XCTAssertEqual(...)
    }
}

@AFutureD
Copy link
Author

Hi @0xTim, I face the problem that there is no place for XCTHTTPClient to write test code.
Can you give me some advice?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant