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

Fighting flakiness: no longer uses beCloseToDate in CustomerInfoOfflineEntitlementsStoreKitTest.verifyEntitlement #4399

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/OfflineEntitlements/PurchasedSK2Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension PurchasedSK2Product {
self.entitlement = .init(
expiresDate: expiration,
productIdentifier: transaction.productID,
purchaseDate: Date(),
purchaseDate: transaction.purchaseDate,
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this is an actual implementation change. However, using the transaction date might be more correct? This was introduced in #2358, but there are no details on this particular property. Let me know if this is actually not what we want.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems this is only used for offline entitlements and conceptually it makes sense. Also checked on Android and seems this is the logic we use there so I think it's ok...

But I would like someone from @RevenueCat/catforms to double-check.

rawData: (try? transaction.jsonRepresentation.asJSONDictionary()) ?? [:]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class CustomerInfoOfflineEntitlementsStoreKitTest: StoreKitConfigTestCase {
productID: transaction.productID,
entitlementID: entitlementID,
periodType: .trial,
expiration: transaction.expirationDate)
expiration: transaction.expirationDate,
originalPurchaseDate: transaction.originalPurchaseDate,
latestPurchaseDate: transaction.originalPurchaseDate)
}

func testRawData() async throws {
Expand Down Expand Up @@ -102,12 +104,16 @@ class CustomerInfoOfflineEntitlementsStoreKitTest: StoreKitConfigTestCase {
productID: transaction.productID,
entitlementID: entitlement1,
periodType: .trial,
expiration: transaction.expirationDate)
expiration: transaction.expirationDate,
originalPurchaseDate: transaction.originalPurchaseDate,
latestPurchaseDate: transaction.originalPurchaseDate)
try self.verifyEntitlement(info.entitlements[entitlement2],
productID: transaction.productID,
entitlementID: entitlement2,
periodType: .trial,
expiration: transaction.expirationDate)
expiration: transaction.expirationDate,
originalPurchaseDate: transaction.originalPurchaseDate,
latestPurchaseDate: transaction.originalPurchaseDate)
}

func testProductNotFoundInMapping() async throws {
Expand Down Expand Up @@ -166,17 +172,23 @@ class CustomerInfoOfflineEntitlementsStoreKitTest: StoreKitConfigTestCase {
productID: product1.id,
entitlementID: entitlement1,
periodType: .trial,
expiration: transaction1.expirationDate)
expiration: transaction1.expirationDate,
originalPurchaseDate: transaction1.originalPurchaseDate,
latestPurchaseDate: transaction1.originalPurchaseDate)
try self.verifyEntitlement(info.entitlements[entitlement2],
productID: product2.id,
entitlementID: entitlement2,
periodType: .normal,
expiration: transaction2.expirationDate)
expiration: transaction2.expirationDate,
originalPurchaseDate: transaction2.originalPurchaseDate,
latestPurchaseDate: transaction2.originalPurchaseDate)
try self.verifyEntitlement(info.entitlements[entitlement3],
productID: product2.id,
entitlementID: entitlement3,
periodType: .normal,
expiration: transaction2.expirationDate)
expiration: transaction2.expirationDate,
originalPurchaseDate: transaction2.originalPurchaseDate,
latestPurchaseDate: transaction2.originalPurchaseDate)
}

func testOverlappingEntitlementsPrioritizeLongestExpiration() async throws {
Expand Down Expand Up @@ -205,7 +217,9 @@ class CustomerInfoOfflineEntitlementsStoreKitTest: StoreKitConfigTestCase {
productID: product2.id,
entitlementID: entitlementID,
periodType: .normal,
expiration: transaction2.expirationDate)
expiration: transaction2.expirationDate,
originalPurchaseDate: transaction2.originalPurchaseDate,
latestPurchaseDate: transaction2.originalPurchaseDate)
}

}
Expand Down Expand Up @@ -236,12 +250,15 @@ private extension CustomerInfoOfflineEntitlementsStoreKitTest {
expect(info.originalPurchaseDate).to(beCloseToNow())
}

// swiftlint:disable:next function_parameter_count
func verifyEntitlement(
_ entitlement: EntitlementInfo?,
productID: String,
entitlementID: String,
periodType: PeriodType,
expiration: Date?,
originalPurchaseDate: Date,
latestPurchaseDate: Date,
file: FileString = #file,
line: UInt = #line
) throws {
Expand All @@ -252,13 +269,13 @@ private extension CustomerInfoOfflineEntitlementsStoreKitTest {
expect(entitlement.productIdentifier) == productID
expect(entitlement.billingIssueDetectedAt).to(beNil())
if let expiration = expiration {
expect(entitlement.expirationDate).to(beCloseToDate(expiration))
expect(entitlement.expirationDate) == expiration
} else {
expect(entitlement.expirationDate).to(beNil())
}
expect(entitlement.isSandbox) == self.sandboxDetector.isSandbox
expect(entitlement.originalPurchaseDate).to(beCloseToNow())
expect(entitlement.latestPurchaseDate).to(beCloseToNow())
expect(entitlement.originalPurchaseDate) == originalPurchaseDate
expect(entitlement.latestPurchaseDate) == latestPurchaseDate
expect(entitlement.ownershipType) == .purchased
expect(entitlement.periodType) == periodType
expect(entitlement.store) == .appStore
Expand Down