Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Jun 13, 2023
1 parent ae56cd5 commit 150e22f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Tests/UnitTests/Networking/HTTPResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,51 @@ class HTTPResponseTests: TestCase {
expect(response.requestDate).to(beNil())
}

func testCopyWithSameVerificationResult() throws {
self.verifyCopy(of: try Self.sampleResponse.copy(with: .verified),
onlyModifiesEntitlementVerification: .verified)
}

func testCopyWithVerificationResultVerified() throws {
self.verifyCopy(of: try Self.sampleResponse,
onlyModifiesEntitlementVerification: .verified)
}

func testCopyWithVerificationResultFailedVerified() throws {
self.verifyCopy(of: try Self.sampleResponse,
onlyModifiesEntitlementVerification: .failed)
}

func testCopyWithVerificationResultNotRequested() throws {
self.verifyCopy(of: try Self.sampleResponse.copy(with: .verified),
onlyModifiesEntitlementVerification: .notRequested)
}

// MARK: -

private func verifyCopy<T: Equatable>(
of response: HTTPResponse<T>,
onlyModifiesEntitlementVerification newVerification: VerificationResult
) {
let copy = response.copy(with: newVerification)
expect(copy.verificationResult) == newVerification
expect(copy.statusCode) == response.statusCode
expect(copy.responseHeaders).to(haveCount(response.responseHeaders.count))
expect(copy.body) == response.body
expect(copy.requestDate) == response.requestDate
}

private static var sampleResponse: HTTPResponse<Data> {
get throws {
return .create(
body: try CustomerInfo.emptyInfo.prettyPrintedData,
headers: [
"X-Header": "true"
]
)
}
}

}

private extension HTTPResponse where Body == HTTPEmptyResponseBody {
Expand All @@ -90,6 +135,18 @@ private extension HTTPResponse where Body == HTTPEmptyResponseBody {

}

private extension HTTPResponse where Body == Data {

static func create(body: Data, headers: HTTPResponse.Headers) -> Self {
return .init(statusCode: .success,
responseHeaders: headers,
body: body,
requestDate: Date(),
verificationResult: .notRequested)
}

}

// MARK: - HTTPResponseBody

class HTTPResponseBodyTests: TestCase {
Expand Down

0 comments on commit 150e22f

Please sign in to comment.