Skip to content

Commit

Permalink
add new feature flag with tests (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkicks authored Sep 13, 2023
1 parent 24e0c7b commit aaf8e72
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class RemoteConfigFeatureFlagToolsViewControllerTests: TestCase {
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: false,
RemoteConfigFeature.facebookLoginInterstitialEnabled
.rawValue: false,
RemoteConfigFeature.reportThisProjectEnabled.rawValue: false,
RemoteConfigFeature.creatorDashboardEnabled
.rawValue: false
]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public func featureFacebookLoginInterstitialEnabled() -> Bool {
.isFeatureEnabled(featureKey: RemoteConfigFeature.facebookLoginInterstitialEnabled) ?? false)
}

public func featureReportThisProjectEnabled() -> Bool {
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.reportThisProjectEnabled.rawValue] ??
(AppEnvironment.current.remoteConfigClient?
.isFeatureEnabled(featureKey: RemoteConfigFeature.reportThisProjectEnabled) ?? false)
}

public func featureUseOfAIProjectTabEnabled() -> Bool {
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.useOfAIProjectTab.rawValue] ??
Expand Down
18 changes: 18 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature+HelpersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ final class RemoteConfigFeatureHelpersTests: TestCase {
}
}

func testReportThisProject_RemoteConfig_FeatureFlag_True() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.reportThisProjectEnabled.rawValue: true]

withEnvironment(remoteConfigClient: mockRemoteConfigClient) {
XCTAssertTrue(featureReportThisProjectEnabled())
}
}

func testReportThisProject_RemoteConfig_FeatureFlag_False() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.reportThisProjectEnabled.rawValue: false]

withEnvironment(remoteConfigClient: mockRemoteConfigClient) {
XCTAssertFalse(featureReportThisProjectEnabled())
}
}

func testUseOfAIProjectTab_RemoteConfig_FeatureFlag_False() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.useOfAIProjectTab.rawValue: false]
Expand Down
2 changes: 2 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum RemoteConfigFeature: String, CaseIterable {
case consentManagementDialogEnabled = "consent_management_dialog"
case creatorDashboardEnabled = "creator_dashboard"
case facebookLoginInterstitialEnabled = "facebook_interstitial"
case reportThisProjectEnabled = "report_this_project"
case useOfAIProjectTab = "use_of_ai_project_tab"
}

Expand All @@ -13,6 +14,7 @@ extension RemoteConfigFeature: CustomStringConvertible {
case .consentManagementDialogEnabled: return "Consent Management Dialog"
case .creatorDashboardEnabled: return "Creator Dashboard"
case .facebookLoginInterstitialEnabled: return "Facebook Login Interstitial"
case .reportThisProjectEnabled: return "Report This Project"
case .useOfAIProjectTab: return "Use of AI Project Tab"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ private func isFeatureEnabled(_ feature: RemoteConfigFeature) -> Bool {
return featureFacebookLoginInterstitialEnabled()
case .creatorDashboardEnabled:
return featureCreatorDashboardEnabled()
case .reportThisProjectEnabled:
return featureReportThisProjectEnabled()
case .useOfAIProjectTab:
return featureUseOfAIProjectTabEnabled()
}
Expand All @@ -109,6 +111,9 @@ private func getValueFromUserDefaults(for feature: RemoteConfigFeature) -> Bool?
case .creatorDashboardEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.creatorDashboardEnabled.rawValue]
case .reportThisProjectEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.reportThisProjectEnabled.rawValue]
case .useOfAIProjectTab:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.useOfAIProjectTab.rawValue]
Expand All @@ -128,6 +133,9 @@ private func setValueInUserDefaults(for feature: RemoteConfigFeature, and value:
case .creatorDashboardEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.creatorDashboardEnabled.rawValue] = value
case .reportThisProjectEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.reportThisProjectEnabled.rawValue] = value
case .useOfAIProjectTab:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.useOfAIProjectTab.rawValue] = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true,
RemoteConfigFeature.creatorDashboardEnabled.rawValue: true,
RemoteConfigFeature.reportThisProjectEnabled.rawValue: true,
RemoteConfigFeature.useOfAIProjectTab.rawValue: true
]

Expand All @@ -47,6 +48,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true,
RemoteConfigFeature.creatorDashboardEnabled.rawValue: false,
RemoteConfigFeature.reportThisProjectEnabled.rawValue: false,
RemoteConfigFeature.useOfAIProjectTab.rawValue: false
]

Expand Down

0 comments on commit aaf8e72

Please sign in to comment.