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

HTTPClient: added test for 2xx response for request with etag #2361

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions Tests/UnitTests/Networking/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,35 @@ final class HTTPClientTests: BaseHTTPClientTests {
expect(result?.value?.body) == responseData
}

func testServerSide200WithETagInRequest() {
let request = HTTPRequest(method: .get, path: .mockPath)
let responseData = "{\"message\": \"something is great up in the cloud\"}".asData
let eTag = "etag"

self.eTagManager.stubResponseEtag(eTag)

stub(condition: isPath(request.path)) { request in
expect(request.allHTTPHeaderFields?[ETagManager.eTagRequestHeaderName]) == eTag

return HTTPStubsResponse(data: responseData,
statusCode: .success,
headers: nil)
}

let result = waitUntilValue { completion in
self.client.perform(request) { (response: HTTPResponse<Data>.Result) in
completion(response)
}
}

expect(result).toNot(beNil())
expect(result).to(beSuccess())
expect(result?.value?.body) == responseData

expect(self.eTagManager.invokedHTTPResultFromCacheOrBackend) == true
expect(self.eTagManager.invokedHTTPResultFromCacheOrBackendCount) == 1
}

func testResponseDeserialization() throws {
struct CustomResponse: Codable, Equatable, HTTPResponseBody {
let message: String
Expand Down