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

Add attribute for checking for deprecated Mac remote message interaction #903

Merged
merged 2 commits into from
Jul 19, 2024
Merged
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
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
)
}
}
Loading