Skip to content

Commit

Permalink
Add new deprecated Mac remote message attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Jul 19, 2024
1 parent 3d9d860 commit 3c068c6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private enum AttributesKey: String, CaseIterable {
case pproPurchasePlatform
case pproSubscriptionStatus
case interactedWithMessage
case interactedWithDeprecatedMacRemoteMessage
case installedMacAppStore
case pinnedTabs
case customHomePage
Expand Down Expand Up @@ -74,6 +75,9 @@ private enum AttributesKey: String, CaseIterable {
case .pproPurchasePlatform: return PrivacyProPurchasePlatformMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute)
case .pproSubscriptionStatus: return PrivacyProSubscriptionStatusMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute)
case .interactedWithMessage: return InteractedWithMessageMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute)
case .interactedWithDeprecatedMacRemoteMessage: return InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(
jsonMatchingAttribute: jsonMatchingAttribute
)
case .installedMacAppStore: return IsInstalledMacAppStoreMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute)
case .pinnedTabs: return PinnedTabsMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute)
case .customHomePage: return CustomHomePageMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute)
Expand Down
13 changes: 12 additions & 1 deletion Sources/RemoteMessaging/Matchers/UserAttributeMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public struct DesktopUserAttributeMatcher: AttributeMatching {
private let hasCustomHomePage: Bool
private let isDuckPlayerOnboarded: Bool
private let isDuckPlayerEnabled: Bool
private let dismissedDeprecatedMacRemoteMessageIds: [String]

private let commonUserAttributeMatcher: CommonUserAttributeMatcher

Expand All @@ -116,12 +117,14 @@ public struct DesktopUserAttributeMatcher: AttributeMatching {
pinnedTabsCount: Int,
hasCustomHomePage: Bool,
isDuckPlayerOnboarded: Bool,
isDuckPlayerEnabled: Bool
isDuckPlayerEnabled: Bool,
dismissedDeprecatedMacRemoteMessageIds: [String]
) {
self.pinnedTabsCount = pinnedTabsCount
self.hasCustomHomePage = hasCustomHomePage
self.isDuckPlayerOnboarded = isDuckPlayerOnboarded
self.isDuckPlayerEnabled = isDuckPlayerEnabled
self.dismissedDeprecatedMacRemoteMessageIds = dismissedDeprecatedMacRemoteMessageIds

commonUserAttributeMatcher = .init(
statisticsStore: statisticsStore,
Expand Down Expand Up @@ -153,6 +156,14 @@ public struct DesktopUserAttributeMatcher: AttributeMatching {
return matchingAttribute.evaluate(for: isDuckPlayerOnboarded)
case let matchingAttribute as DuckPlayerEnabledMatchingAttribute:
return matchingAttribute.evaluate(for: isDuckPlayerEnabled)
case let matchingAttribute as InteractedWithDeprecatedMacRemoteMessageMatchingAttribute:
if dismissedDeprecatedMacRemoteMessageIds.contains(where: { messageId in
StringArrayMatchingAttribute(matchingAttribute.value).matches(value: messageId) == .match
}) {
return .match
} else {
return .fail
}
default:
return commonUserAttributeMatcher.evaluate(matchingAttribute: matchingAttribute)
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/RemoteMessaging/Model/MatchingAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ struct InteractedWithMessageMatchingAttribute: SingleValueMatching {
var fallback: Bool?
}

struct InteractedWithDeprecatedMacRemoteMessageMatchingAttribute: SingleValueMatching {
var value: [String]? = []
var fallback: Bool?
}

struct IsInstalledMacAppStoreMatchingAttribute: SingleValueMatching {
var value: Bool?
var fallback: Bool?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DesktopUserAttributeMatcherTests: XCTestCase {
emailManagerStorage.mockToken = "token"

emailManager = EmailManager(storage: emailManagerStorage)
setUpUserAttributeMatcher()
setUpUserAttributeMatcher(dismissedDeprecatedMacRemoteMessageIds: ["dismissed-message"])
}

override func tearDownWithError() throws {
Expand Down Expand Up @@ -133,9 +133,37 @@ class DesktopUserAttributeMatcherTests: XCTestCase {
.fail)
}

// MARK: - DeprecatedMacRemoteMessage

func testWhenNoDismissedMessageIdsAreProvidedThenReturnFail() throws {
XCTAssertEqual(matcher.evaluate(
matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: [], fallback: nil)
), .fail)
}

func testWhenNoDismissedMessageIdsMatchThenReturnFail() throws {
XCTAssertEqual(matcher.evaluate(
matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: ["unrelated-message"], fallback: nil)
), .fail)
}

func testWhenOneDismissedMessageIdMatchesThenReturnMatch() throws {
XCTAssertEqual(matcher.evaluate(
matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: ["dismissed-message"], fallback: nil)
), .match)
}

func testWhenTwoDismissedMessageIdsMatchThenReturnMatch() throws {
XCTAssertEqual(matcher.evaluate(
matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: [
"dismissed-message", "unrelated-message"
], fallback: nil)
), .match)
}

// MARK: -

private func setUpUserAttributeMatcher(dismissedMessageIds: [String] = []) {
private func setUpUserAttributeMatcher(dismissedMessageIds: [String] = [], dismissedDeprecatedMacRemoteMessageIds: [String] = []) {
matcher = DesktopUserAttributeMatcher(
statisticsStore: mockStatisticsStore,
variantManager: manager,
Expand All @@ -156,7 +184,8 @@ class DesktopUserAttributeMatcherTests: XCTestCase {
pinnedTabsCount: 3,
hasCustomHomePage: true,
isDuckPlayerOnboarded: true,
isDuckPlayerEnabled: false
isDuckPlayerEnabled: false,
dismissedDeprecatedMacRemoteMessageIds: dismissedDeprecatedMacRemoteMessageIds
)
}
}

0 comments on commit 3c068c6

Please sign in to comment.