Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,16 @@ enum InternalSuperwallEvent {
var params = paywallInfo.audienceFilterParams()
if let product = product {
params["abandoned_product_id"] = product.productIdentifier
let hasRicherProductAttributes =
!product.localizedPrice.isEmpty
|| !product.localizedSubscriptionPeriod.isEmpty
|| !product.period.isEmpty
Comment thread
yusuftor marked this conversation as resolved.

if hasRicherProductAttributes {
for (key, value) in product.attributes {
params["abandoned_product_\(key.camelCaseToSnakeCase())"] = value
}
}
}
return params
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,43 @@ struct TrackingTests {
result.parameters.audienceFilterParams["presented_by_event_name"] as? String == paywallInfo.presentedByPlacementWithName)
}

@Test func transaction_abandon() async {
let paywallInfo: PaywallInfo = .stub()
let productId = "abc"
let product = StoreProduct(
sk1Product: MockSkProduct(productIdentifier: productId),
entitlements: [.stub()]
)
let dependencyContainer = DependencyContainer()
let skTransaction = MockSKPaymentTransaction(state: .purchased)
let transaction = await dependencyContainer.makeStoreTransaction(from: skTransaction)
let result = await Superwall.shared.track(
InternalSuperwallEvent.Transaction(
state: .abandon(product),
paywallInfo: paywallInfo,
product: product,
transaction: transaction,
source: .external,
isObserved: false,
storeKitVersion: .storeKit1
)
)

#expect(result.parameters.audienceFilterParams["$event_name"] as! String == "transaction_abandon")
#expect(result.parameters.audienceFilterParams["$product_period"] != nil)
#expect(result.parameters.audienceFilterParams["$product_period_months"] != nil)

#expect(
result.parameters.audienceFilterParams["event_name"] as! String == "transaction_abandon")
#expect(
result.parameters.audienceFilterParams["abandoned_product_id"] as! String == productId)
#expect(result.parameters.audienceFilterParams["abandoned_product_identifier"] as! String == productId)
#expect(result.parameters.audienceFilterParams["abandoned_product_period"] != nil)
#expect(result.parameters.audienceFilterParams["abandoned_product_period_months"] != nil)
#expect(result.parameters.audienceFilterParams["abandoned_product_period_years"] != nil)
#expect(result.parameters.audienceFilterParams["abandoned_product_localized_period"] != nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 != nil assertions don't verify period values are meaningful

periodMonthsString, periodYearsString, etc. return "" (empty string) for non-subscription products, and an empty string is still non-nil — so these assertions pass even when the feature has not populated real period data. Consider asserting the expected string values from MockSkProduct's configured period, or at least asserting as? String != "" to confirm the fields are actually populated.

Prompt To Fix With AI
This is a comment left during a code review.
Path: Tests/SuperwallKitTests/Analytics/Internal Tracking/TrackTests.swift
Line: 1729-1732

Comment:
**`!= nil` assertions don't verify period values are meaningful**

`periodMonthsString`, `periodYearsString`, etc. return `""` (empty string) for non-subscription products, and an empty string is still non-nil — so these assertions pass even when the feature has not populated real period data. Consider asserting the expected string values from `MockSkProduct`'s configured period, or at least asserting `as? String != ""` to confirm the fields are actually populated.

How can I resolve this? If you propose a fix, please make it concise.

}

@Test func transaction_fail() async {
let paywallInfo: PaywallInfo = .stub()
let productId = "abc"
Expand Down