Skip to content

Commit

Permalink
NetworkError: 2 new tests to ensure underlying error is included in…
Browse files Browse the repository at this point in the history
… description

This has been improved significantly (like #1974). I wrote these tests to see if I could reproduce why the logs in RevenueCat/purchases-flutter#766 don't include the underlying error.
It's likely that's using an old version of the SDK, but these tests are still useful.
  • Loading branch information
NachoSoto committed Jul 23, 2023
1 parent aea0114 commit f64d58e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Tests/UnitTests/Networking/BackendErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import XCTest

class BackendErrorTests: BaseErrorTests {

func testNetworkError() {
let underlyingError = NSError(domain: NSURLErrorDomain, code: NSURLErrorDNSLookupFailed)

let error: BackendError = .networkError(
.networkError(underlyingError)
)

verifyPurchasesError(error,
expectedCode: .networkError,
underlyingError: underlyingError)
}

func testMissingAppUserID() {
let error: BackendError = .missingAppUserID()

Expand Down
2 changes: 1 addition & 1 deletion Tests/UnitTests/Networking/NetworkErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NetworkErrorAsPurchasesErrorTests: BaseErrorTests {
}

func testNetworkError() {
let underlyingError = NSError(domain: "domain", code: 20)
let underlyingError = NSError(domain: NSURLErrorDomain, code: NSURLErrorCannotFindHost)
let error: NetworkError = .networkError(underlyingError)

verifyPurchasesError(error,
Expand Down
15 changes: 15 additions & 0 deletions Tests/UnitTests/Purchasing/OfferingsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,21 @@ extension OfferingsManagerTests {
expect(self.mockDeviceCache.cacheOfferingsInMemoryCount) == 0
}

func testNetworkErrorContainsUnderlyingError() {
let underlyingError = NSError(domain: NSURLErrorDomain,
code: NSURLErrorCancelledReasonInsufficientSystemResources)

let error: OfferingsManager.Error = .backendError(
.networkError(
.networkError(underlyingError)
)
)
_ = error.asPurchasesError

self.logger.verifyMessageWasLogged("NSURLErrorDomain error \(underlyingError.code)",
level: .error)
}

}

private extension OfferingsManagerTests {
Expand Down

0 comments on commit f64d58e

Please sign in to comment.