Skip to content

Commit

Permalink
Paywalls: renamed PaywallEvent.view to .impression
Browse files Browse the repository at this point in the history
Suggested by @aboedo, makes this less ambiguous with `PaywallView`.
  • Loading branch information
NachoSoto committed Sep 14, 2023
1 parent 66b5048 commit c02567f
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ struct LoadedOfferingPaywallView: View {
.preference(key: RestoredCustomerInfoPreferenceKey.self,
value: self.purchaseHandler.restoredCustomerInfo)
.disabled(self.purchaseHandler.actionInProgress)
.onAppear { self.purchaseHandler.trackPaywallView(self.eventData) }
.onAppear { self.purchaseHandler.trackPaywallImpression(self.eventData) }
.onDisappear { self.purchaseHandler.trackPaywallClose(self.eventData) }

switch self.mode {
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Purchasing/PurchaseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ extension PurchaseHandler {
return customerInfo
}

func trackPaywallView(_ eventData: PaywallEvent.Data) {
func trackPaywallImpression(_ eventData: PaywallEvent.Data) {
self.eventData = eventData
self.track(.view(eventData))
self.track(.impression(eventData))
}

func trackPaywallClose(_ eventData: PaywallEvent.Data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private extension PaywallEvent {

var eventType: PaywallEventsRequest.EventType {
switch self {
case .view: return .impression
case .impression: return .impression
case .cancel: return .cancel
case .close: return .close
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Paywalls/Events/PaywallEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum PaywallEvent {
public typealias SessionID = UUID

/// A `PaywallView` was displayed.
case view(Data)
case impression(Data)

/// A purchase was cancelled.
case cancel(Data)
Expand Down Expand Up @@ -92,7 +92,7 @@ extension PaywallEvent {
/// - Returns: the underlying ``PaywallEvent/Data-swift.struct`` for this event.
public var data: Data {
switch self {
case let .view(data): return data
case let .impression(data): return data
case let .cancel(data): return data
case let .close(data): return data
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Purchasing/Purchases/PurchasesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ final class PurchasesOrchestrator {

func track(paywallEvent: PaywallEvent) {
switch paywallEvent {
case let .view(data):
case let .impression(data):
self.cachePresentedPaywall(data)

case .close:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func checkPaywallEvent(_ event: PaywallEvent) {
let _: PaywallEvent.SessionID = UUID()

switch event {
case let .view(data): checkPaywallEventData(data)
case let .impression(data): checkPaywallEventData(data)
case let .cancel(data): checkPaywallEventData(data)
case let .close(data): checkPaywallEventData(data)
@unknown default: break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class PaywallEventsIntegrationTests: BaseStoreKitIntegrationTests {
}

func testPurchasingPackageWithPresentedPaywall() async throws {
try await self.purchases.track(paywallEvent: .view(self.eventData))
try await self.purchases.track(paywallEvent: .impression(self.eventData))

let transaction = try await XCTAsyncUnwrap(try await self.purchases.purchase(package: package).transaction)

self.verifyTransactionHandled(with: transaction, sessionID: self.eventData.sessionIdentifier)
}

func testPurchasingPackageAfterClearingPresentedPaywall() async throws {
try await self.purchases.track(paywallEvent: .view(self.eventData))
try await self.purchases.track(paywallEvent: .impression(self.eventData))
try await self.purchases.track(paywallEvent: .close(self.eventData))

let transaction = try await XCTAsyncUnwrap(try await self.purchases.purchase(package: self.package).transaction)
Expand All @@ -62,7 +62,7 @@ class PaywallEventsIntegrationTests: BaseStoreKitIntegrationTests {
self.testSession.failTransactionsEnabled = true
self.testSession.failureError = .unknown

try await self.purchases.track(paywallEvent: .view(self.eventData))
try await self.purchases.track(paywallEvent: .impression(self.eventData))

do {
_ = try await self.purchases.purchase(package: self.package)
Expand All @@ -85,7 +85,7 @@ class PaywallEventsIntegrationTests: BaseStoreKitIntegrationTests {
}

func testFlushingEvents() async throws {
try await self.purchases.track(paywallEvent: .view(self.eventData))
try await self.purchases.track(paywallEvent: .impression(self.eventData))
try await self.purchases.track(paywallEvent: .cancel(self.eventData))
try await self.purchases.track(paywallEvent: .close(self.eventData))

Expand All @@ -94,7 +94,7 @@ class PaywallEventsIntegrationTests: BaseStoreKitIntegrationTests {
}

func testFlushingEventsClearsThem() async throws {
try await self.purchases.track(paywallEvent: .view(self.eventData))
try await self.purchases.track(paywallEvent: .impression(self.eventData))
try await self.purchases.track(paywallEvent: .cancel(self.eventData))
try await self.purchases.track(paywallEvent: .close(self.eventData))

Expand All @@ -104,7 +104,7 @@ class PaywallEventsIntegrationTests: BaseStoreKitIntegrationTests {
}

func testRemembersEventsWhenReopeningApp() async throws {
try await self.purchases.track(paywallEvent: .view(self.eventData))
try await self.purchases.track(paywallEvent: .impression(self.eventData))
try await self.purchases.track(paywallEvent: .close(self.eventData))

await self.resetSingleton()
Expand Down
28 changes: 14 additions & 14 deletions Tests/RevenueCatUITests/PaywallViewEventsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PaywallViewEventsTests: TestCase {
private let mode: PaywallViewMode = .random
private let scheme: ColorScheme = Bool.random() ? .dark : .light

private var viewEventExpectation: XCTestExpectation!
private var impressionEventExpectation: XCTestExpectation!
private var closeEventExpectation: XCTestExpectation!
private var cancelEventExpectation: XCTestExpectation!

Expand All @@ -44,12 +44,12 @@ class PaywallViewEventsTests: TestCase {
}
}

self.viewEventExpectation = .init(description: "View event")
self.impressionEventExpectation = .init(description: "Impression event")
self.closeEventExpectation = .init(description: "Close event")
self.cancelEventExpectation = .init(description: "Cancel event")
}

func testPaywallViewEvent() async throws {
func testPaywallImpressionEvent() async throws {
let expectation = XCTestExpectation()

try self.createView()
Expand All @@ -58,9 +58,9 @@ class PaywallViewEventsTests: TestCase {

await self.fulfillment(of: [expectation], timeout: 1)

expect(self.events).to(containElementSatisfying { $0.eventType == .view })
expect(self.events).to(containElementSatisfying { $0.eventType == .impression })

let event = try XCTUnwrap(self.events.first { $0.eventType == .view })
let event = try XCTUnwrap(self.events.first { $0.eventType == .impression })
self.verifyEventData(event.data)
}

Expand All @@ -73,7 +73,7 @@ class PaywallViewEventsTests: TestCase {
expect(self.events).to(haveCount(2))
expect(self.events).to(containElementSatisfying { $0.eventType == .close })

let event = try XCTUnwrap(self.events.first { $0.eventType == .view })
let event = try XCTUnwrap(self.events.first { $0.eventType == .impression })
self.verifyEventData(event.data)
}

Expand All @@ -84,7 +84,7 @@ class PaywallViewEventsTests: TestCase {
await self.fulfillment(of: [self.closeEventExpectation], timeout: 1)

expect(self.events).to(haveCount(2))
expect(self.events.map(\.eventType)) == [.view, .close]
expect(self.events.map(\.eventType)) == [.impression, .close]
expect(Set(self.events.map(\.data.sessionIdentifier))).to(haveCount(1))
}

Expand All @@ -98,15 +98,15 @@ class PaywallViewEventsTests: TestCase {
timeout: 1)

expect(self.events).to(haveCount(3))
expect(self.events.map(\.eventType)).to(contain([.view, .cancel, .close]))
expect(self.events.map(\.eventType)).to(contain([.impression, .cancel, .close]))
expect(Set(self.events.map(\.data.sessionIdentifier))).to(haveCount(1))

let data = try XCTUnwrap(self.events.first { $0.eventType == .cancel }).data
self.verifyEventData(data)
}

func testDifferentPaywallsCreateSeparateSessionIdentifiers() async throws {
self.viewEventExpectation.expectedFulfillmentCount = 2
self.impressionEventExpectation.expectedFulfillmentCount = 2
self.closeEventExpectation.expectedFulfillmentCount = 2

let firstCloseExpectation = XCTestExpectation(description: "First paywall was closed")
Expand All @@ -120,10 +120,10 @@ class PaywallViewEventsTests: TestCase {
try self.createView()
.addToHierarchy()

await self.fulfillment(of: [self.viewEventExpectation, self.closeEventExpectation], timeout: 1)
await self.fulfillment(of: [self.impressionEventExpectation, self.closeEventExpectation], timeout: 1)

expect(self.events).to(haveCount(4))
expect(self.events.map(\.eventType)) == [.view, .close, .view, .close]
expect(self.events.map(\.eventType)) == [.impression, .close, .impression, .close]
expect(Set(self.events.map(\.data.sessionIdentifier))).to(haveCount(2))
}

Expand All @@ -140,7 +140,7 @@ private extension PaywallViewEventsTests {
self.events.append(event)

switch event {
case .view: self.viewEventExpectation.fulfill()
case .impression: self.impressionEventExpectation.fulfill()
case .cancel: self.cancelEventExpectation.fulfill()
case .close: self.closeEventExpectation.fulfill()
}
Expand Down Expand Up @@ -179,15 +179,15 @@ private extension PaywallEvent {

enum EventType {

case view
case impression
case cancel
case close

}

var eventType: EventType {
switch self {
case .view: return .view
case .impression: return .impression
case .cancel: return .cancel
case .close: return .close
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/StoreKitUnitTests/PurchasesOrchestratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {
let product = try await self.fetchSk1Product()
let payment = self.storeKit1Wrapper.payment(with: product)

self.orchestrator.track(paywallEvent: .view(Self.paywallEvent))
self.orchestrator.track(paywallEvent: .impression(Self.paywallEvent))

_ = await withCheckedContinuation { continuation in
self.orchestrator.purchase(
Expand Down Expand Up @@ -299,7 +299,7 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {
}
}

self.orchestrator.track(paywallEvent: .view(Self.paywallEvent))
self.orchestrator.track(paywallEvent: .impression(Self.paywallEvent))
self.customerInfoManager.stubbedCachedCustomerInfoResult = self.mockCustomerInfo

self.backend.stubbedPostReceiptResult = .failure(.unexpectedBackendResponse(.customerInfoNil))
Expand Down Expand Up @@ -720,7 +720,7 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {

self.customerInfoManager.stubbedCachedCustomerInfoResult = self.mockCustomerInfo
self.backend.stubbedPostReceiptResult = .success(self.mockCustomerInfo)
self.orchestrator.track(paywallEvent: .view(Self.paywallEvent))
self.orchestrator.track(paywallEvent: .impression(Self.paywallEvent))

let mockListener = try XCTUnwrap(
self.orchestrator.storeKit2TransactionListener as? MockStoreKit2TransactionListener
Expand All @@ -747,7 +747,7 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {

let product = try await self.fetchSk2Product()

self.orchestrator.track(paywallEvent: .view(Self.paywallEvent))
self.orchestrator.track(paywallEvent: .impression(Self.paywallEvent))

self.customerInfoManager.stubbedCachedCustomerInfoResult = self.mockCustomerInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class PaywallEventSerializerTests: TestCase {
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()
}

func testEncodeViewEvent() throws {
let event: PaywallStoredEvent = .init(event: .view(.random()), userID: Self.userID)
func testEncodeImpressionEvent() throws {
let event: PaywallStoredEvent = .init(event: .impression(.random()), userID: Self.userID)

let encoded = try PaywallEventSerializer.encode(event)
let decoded: PaywallStoredEvent = try JSONDecoder.default.decode(jsonData: encoded.asData)
Expand All @@ -34,8 +34,8 @@ class PaywallEventSerializerTests: TestCase {
expect(decoded) == event
}

func testDecodeViewEvent() throws {
let event: PaywallStoredEvent = .init(event: .view(.random()), userID: Self.userID)
func testDecodeImpressionEvent() throws {
let event: PaywallStoredEvent = .init(event: .impression(.random()), userID: Self.userID)
expect(try event.encodeAndDecode()) == event
}

Expand Down
Loading

0 comments on commit c02567f

Please sign in to comment.