Skip to content

IntegrationTests: simplified tests using async APIs#1332

Merged
NachoSoto merged 1 commit into
mainfrom
integration-tests-async
Feb 23, 2022
Merged

IntegrationTests: simplified tests using async APIs#1332
NachoSoto merged 1 commit into
mainfrom
integration-tests-async

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Feb 22, 2022

Copy link
Copy Markdown
Contributor

Improvements:

  • No more expect(completed).toEventually(beTrue()).
  • No more expect(error).to(beNil()). Using try and throws tests.
  • No more expect(result).toNot(beNil()) or XCTUnwrap. The new APIs already return non-optional data when not failed.
  • No more toEventuallys + polling. Tests run serially now without busy waiting, which will make them faster.
  • No more completion block trees, tests are linear now.

Other changes:

  • Removed empty optional purchases(_:, shouldPurchasePromoProduct:, defermentBlock:).
  • Using modern == Nimble methods.
  • Removed redundant syncPurchases call when purchasing.

@NachoSoto NachoSoto requested review from a team and aboedo February 22, 2022 16:58
@NachoSoto NachoSoto force-pushed the integration-tests-async branch from 04188d2 to 5c5b663 Compare February 22, 2022 17:16
Improvements:
- No more `expect(completed).toEventually(beTrue())`.
- No more `expect(error).to(beNil())`. Using `try` and `throws` tests.
- No more `expect(result).toNot(beNil())` or `XCTUnwrap`. The new APIs already return non-optional data when not failed.
- No more `toEventually`s + polling. Tests run serially now without busy waiting, which will make them faster.
- No more completion block trees, tests are linear now.

Other changes:
- Removed empty optional `purchases(_:, shouldPurchasePromoProduct:, defermentBlock:)`.
- Using modern `==` Nimble methods.
- Removed redundant `syncPurchases` call when purchasing.
@NachoSoto NachoSoto force-pushed the integration-tests-async branch from 5c5b663 to 51b1e58 Compare February 22, 2022 17:16
expect(unwrappedOfferings.all).toNot(beEmpty())
func testCanGetOfferings() async throws {
let receivedOfferings = try await Purchases.shared.offerings()
expect(receivedOfferings.all).toNot(beEmpty())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is now only 2 lines 🤪

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might cry

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this refactor made my week 🏆

expect(unwrappedOfferings.all).toNot(beEmpty())
func testCanGetOfferings() async throws {
let receivedOfferings = try await Purchases.shared.offerings()
expect(receivedOfferings.all).toNot(beEmpty())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might cry

expect(completionCalled).toEventually(beTrue(), timeout: Self.timeout)
let (identifiedCustomerInfo, created) = try await Purchases.shared.logIn(identifiedUserID)
expect(created) == true
expect(identifiedCustomerInfo.entitlements["premium"]?.isActive) == true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so easy to read now

Comment on lines +129 to +139
func testLogInReturnsCreatedTrueWhenNewAndFalseWhenExisting() async throws {
let anonUserID = Purchases.shared.appUserID
let identifiedUserID = "\(#function)_\(anonUserID)".replacingOccurrences(of: "RCAnonymous", with: "")

var completionCalled = false
Purchases.shared.logIn(identifiedUserID) { identifiedCustomerInfo, created, error in
expect(error).to(beNil())
expect(created).to(beTrue())
Purchases.shared.logOut { loggedOutCustomerInfo, logOutError in
Purchases.shared.logIn(identifiedUserID) { identifiedCustomerInfo, created, error in
expect(error).to(beNil())
expect(created).to(beFalse())
completionCalled = true
}
}
}
var (_, created) = try await Purchases.shared.logIn(identifiedUserID)
expect(created) == true

expect(completionCalled).toEventually(beTrue(), timeout: Self.timeout)
_ = try await Purchases.shared.logOut()

(_, created) = try await Purchases.shared.logIn(identifiedUserID)
expect(created) == false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot overstate my joy

Comment on lines +211 to 214
return try await Purchases.shared
.purchase(package: monthlyPackage)
.customerInfo
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏👏👏👏

@NachoSoto NachoSoto merged commit ae300df into main Feb 23, 2022
@NachoSoto NachoSoto deleted the integration-tests-async branch February 23, 2022 23:10
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.

2 participants