Skip to content

Commit

Permalink
Always call readyForPromotedProduct on the main actor
Browse files Browse the repository at this point in the history
  • Loading branch information
fire-at-will authored Dec 16, 2024
1 parent 793b6f6 commit e78c56d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Sources/Purchasing/Purchases/Purchases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,13 @@ extension Purchases: PurchasesOrchestratorDelegate {
*/
func readyForPromotedProduct(_ product: StoreProduct,
purchase startPurchase: @escaping StartPurchaseBlock) {
self.delegate?.purchases?(self, readyForPromotedProduct: product, purchase: startPurchase)
OperationDispatcher.dispatchOnMainActor {
self.delegate?.purchases?(
self,
readyForPromotedProduct: product,
purchase: startPurchase
)
}
}

#if os(iOS) || targetEnvironment(macCatalyst) || VISION_OS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class PurchaseDeferredPurchasesTests: BasePurchasesTests {
shouldAddStorePayment: payment,
for: self.product)

waitUntil { completed in
if self.purchasesDelegate.makeDeferredPurchase != nil {
completed()
}
}

expect(self.purchasesDelegate.makeDeferredPurchase).toNot(beNil())
expect(self.storeKit1Wrapper.payment).to(beNil())

Expand All @@ -59,6 +65,12 @@ class PurchaseDeferredPurchasesTests: BasePurchasesTests {
shouldAddStorePayment: payment,
for: self.product)

waitUntil { completed in
if self.purchasesDelegate.makeDeferredPurchase != nil {
completed()
}
}

expect(self.purchasesDelegate.makeDeferredPurchase).toNot(beNil())
expect(self.storeKit1Wrapper.payment).to(beNil())

Expand Down Expand Up @@ -87,7 +99,7 @@ class PurchaseDeferredPurchasesTests: BasePurchasesTests {
shouldAddStorePayment: payment,
for: self.product)

expect(self.purchasesDelegate.promoProduct) == StoreProduct(sk1Product: self.product)
expect(self.purchasesDelegate.promoProduct).toEventually(equal(StoreProduct(sk1Product: self.product)))
}

func testShouldAddStorePaymentReturnsFalseForNilProductIdentifier() throws {
Expand Down Expand Up @@ -177,10 +189,9 @@ class PurchaseDeferredPurchasesSK2Tests: BasePurchasesTests {
for: self.product
)

expect(self.purchasesDelegate.makeDeferredPurchase).toNot(beNil())

expect(self.purchasesDelegate.promoProduct) == StoreProduct(sk1Product: self.product)
expect(self.purchasesDelegate.makeDeferredPurchase).toNot(beNil())
expect(self.purchasesDelegate.makeDeferredPurchase).toEventuallyNot(beNil())
expect(self.purchasesDelegate.promoProduct).toEventually(equal(StoreProduct(sk1Product: self.product)))
expect(self.purchasesDelegate.makeDeferredPurchase).toEventuallyNot(beNil())
}

}

0 comments on commit e78c56d

Please sign in to comment.