Skip to content

Commit

Permalink
Update test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed May 31, 2024
1 parent 8864ea2 commit e6f3e36
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
8 changes: 7 additions & 1 deletion Sources/RemoteMessaging/Matchers/UserAttributeMatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public struct UserAttributeMatcher: AttributeMatcher {
private let daysSinceNetPEnabled: Int
private let isPrivacyProEligibleUser: Bool
private let isPrivacyProSubscriber: Bool
private let privacyProDaysSinceSubscribed: Int
private let privacyProDaysUntilExpiry: Int

public init(statisticsStore: StatisticsStore,
variantManager: VariantManager,
Expand All @@ -42,7 +44,9 @@ public struct UserAttributeMatcher: AttributeMatcher {
isWidgetInstalled: Bool,
daysSinceNetPEnabled: Int,
isPrivacyProEligibleUser: Bool,
isPrivacyProSubscriber: Bool
isPrivacyProSubscriber: Bool,
privacyProDaysSinceSubscribed: Int,
privacyProDaysUntilExpiry: Int
) {
self.statisticsStore = statisticsStore
self.variantManager = variantManager
Expand All @@ -54,6 +58,8 @@ public struct UserAttributeMatcher: AttributeMatcher {
self.daysSinceNetPEnabled = daysSinceNetPEnabled
self.isPrivacyProEligibleUser = isPrivacyProEligibleUser
self.isPrivacyProSubscriber = isPrivacyProSubscriber
self.privacyProDaysSinceSubscribed = privacyProDaysSinceSubscribed
self.privacyProDaysUntilExpiry = privacyProDaysUntilExpiry
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ class JsonToRemoteConfigModelMapperTests: XCTestCase {
let rule8 = config.rules.filter { $0.id == 8 }.first
XCTAssertNotNil(rule8)
XCTAssertNil(rule8?.targetPercentile)
XCTAssertTrue(rule8?.attributes.count == 3)
XCTAssertTrue(rule8?.attributes.count == 5)

attribs = rule8?.attributes.filter { $0 is DaysSinceNetPEnabledMatchingAttribute }
XCTAssertEqual(attribs?.count, 1)
XCTAssertEqual(attribs?.first as? DaysSinceNetPEnabledMatchingAttribute, DaysSinceNetPEnabledMatchingAttribute(min: 5, fallback: nil))
Expand All @@ -150,6 +151,16 @@ class JsonToRemoteConfigModelMapperTests: XCTestCase {
IsPrivacyProSubscriberUserMatchingAttribute(value: true, fallback: nil)
)

attribs = rule8?.attributes.filter { $0 is PrivacyProDaysSinceSubscribedMatchingAttribute }
XCTAssertEqual(attribs?.first as? PrivacyProDaysSinceSubscribedMatchingAttribute, PrivacyProDaysSinceSubscribedMatchingAttribute(
min: 5, max: 8, fallback: nil
))

attribs = rule8?.attributes.filter { $0 is PrivacyProDaysUntilExpiryMatchingAttribute }
XCTAssertEqual(attribs?.first as? PrivacyProDaysUntilExpiryMatchingAttribute, PrivacyProDaysUntilExpiryMatchingAttribute(
min: 25, max: 30, fallback: nil
))

let rule9 = config.rules.filter { $0.id == 9 }.first
XCTAssertNotNil(rule9)
XCTAssertNotNil(rule9?.targetPercentile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class UserAttributeMatcherTests: XCTestCase {
isWidgetInstalled: true,
daysSinceNetPEnabled: 3,
isPrivacyProEligibleUser: true,
isPrivacyProSubscriber: true)
isPrivacyProSubscriber: true,
privacyProDaysSinceSubscribed: 5,
privacyProDaysUntilExpiry: 25)
}

override func tearDownWithError() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: MockRemoteMessagePercentileStore(),
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: []
Expand Down Expand Up @@ -131,7 +133,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: MockRemoteMessagePercentileStore(),
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down Expand Up @@ -227,7 +231,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: MockRemoteMessagePercentileStore(),
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: ["1"])
Expand Down Expand Up @@ -266,7 +272,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: MockRemoteMessagePercentileStore(),
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down Expand Up @@ -301,7 +309,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: percentileStore,
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down Expand Up @@ -334,7 +344,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: percentileStore,
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down Expand Up @@ -367,7 +379,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: percentileStore,
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down Expand Up @@ -400,7 +414,9 @@ class RemoteMessagingConfigMatcherTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: percentileStore,
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class RemoteMessagingConfigProcessorTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: MockRemoteMessagePercentileStore(),
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: []
Expand Down Expand Up @@ -69,7 +71,9 @@ class RemoteMessagingConfigProcessorTests: XCTestCase {
isWidgetInstalled: false,
daysSinceNetPEnabled: -1,
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false),
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
percentileStore: MockRemoteMessagePercentileStore(),
surveyActionMapper: MockRemoteMessageSurveyActionMapper(),
dismissedMessageIds: [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@
},
"pproSubscriber": {
"value": true
},
"pproDaysSinceSubscribed": {
"min": 5,
"max": 8
},
"pproDaysUntilExpiryOrRenewal": {
"min": 25,
"max": 30
}
}
},
Expand Down

0 comments on commit e6f3e36

Please sign in to comment.