Skip to content

Commit

Permalink
add new Block Users feature flag (#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottkicks committed Oct 24, 2023
1 parent f0bf8e5 commit 11adbfc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
Expand Up @@ -22,6 +22,7 @@ final class RemoteConfigFeatureFlagToolsViewControllerTests: TestCase {
func testRemoteConfigFeatureFlagToolsViewController() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.blockUsersEnabled.rawValue: false,
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: false,
RemoteConfigFeature.darkModeEnabled.rawValue: false,
RemoteConfigFeature.facebookLoginInterstitialEnabled
Expand Down
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
@@ -1,5 +1,12 @@
/// Return remote config values either a value from the cloud, if it found one, or a default value based on the provided key

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

public func featureConsentManagementDialogEnabled() -> Bool {
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue] ??
Expand Down
18 changes: 18 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature+HelpersTests.swift
Expand Up @@ -3,6 +3,24 @@ import Prelude
import XCTest

final class RemoteConfigFeatureHelpersTests: TestCase {
func testBlockUsers_RemoteConfig_FeatureFlag_False() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.blockUsersEnabled.rawValue: false]

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

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

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

func testConsentManagementDialog_RemoteConfig_FeatureFlag_False() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [RemoteConfigFeature.consentManagementDialogEnabled.rawValue: false]
Expand Down
2 changes: 2 additions & 0 deletions Library/RemoteConfig/RemoteConfigFeature.swift
@@ -1,6 +1,7 @@
import Foundation

public enum RemoteConfigFeature: String, CaseIterable {
case blockUsersEnabled = "block_users"
case consentManagementDialogEnabled = "consent_management_dialog"
case darkModeEnabled = "dark_mode"
case facebookLoginInterstitialEnabled = "facebook_interstitial"
Expand All @@ -11,6 +12,7 @@ public enum RemoteConfigFeature: String, CaseIterable {
extension RemoteConfigFeature: CustomStringConvertible {
public var description: String {
switch self {
case .blockUsersEnabled: return "Block Users"
case .consentManagementDialogEnabled: return "Consent Management Dialog"
case .darkModeEnabled: return "Dark Mode"
case .facebookLoginInterstitialEnabled: return "Facebook Login Interstitial"
Expand Down
Expand Up @@ -85,6 +85,8 @@ public final class RemoteConfigFeatureFlagToolsViewModel: RemoteConfigFeatureFla

private func isFeatureEnabled(_ feature: RemoteConfigFeature) -> Bool {
switch feature {
case .blockUsersEnabled:
return featureBlockUsersEnabled()
case .consentManagementDialogEnabled:
return featureConsentManagementDialogEnabled()
case .darkModeEnabled:
Expand All @@ -102,6 +104,9 @@ private func isFeatureEnabled(_ feature: RemoteConfigFeature) -> Bool {
*/
private func getValueFromUserDefaults(for feature: RemoteConfigFeature) -> Bool? {
switch feature {
case .blockUsersEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.blockUsersEnabled.rawValue]
case .consentManagementDialogEnabled:
return AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue]
Expand All @@ -124,6 +129,9 @@ private func getValueFromUserDefaults(for feature: RemoteConfigFeature) -> Bool?
*/
private func setValueInUserDefaults(for feature: RemoteConfigFeature, and value: Bool) {
switch feature {
case .blockUsersEnabled:
AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.blockUsersEnabled.rawValue] = value
case .consentManagementDialogEnabled:
AppEnvironment.current.userDefaults
.remoteConfigFeatureFlags[RemoteConfigFeature.consentManagementDialogEnabled.rawValue] = value
Expand Down
Expand Up @@ -22,6 +22,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
func testReloadWithData_AllFeaturesEnabled() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.blockUsersEnabled.rawValue: true,
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true,
RemoteConfigFeature.darkModeEnabled.rawValue: true,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true,
Expand All @@ -45,6 +46,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
func testReloadWithData_FeaturesEnabledAndDisabled() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.blockUsersEnabled.rawValue: false,
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true,
RemoteConfigFeature.darkModeEnabled.rawValue: false,
RemoteConfigFeature.facebookLoginInterstitialEnabled.rawValue: true,
Expand Down Expand Up @@ -91,7 +93,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
func testUpdateUserDefaultsWithFeatures_ReloadWithData_UserDefaultsIsUpdated() {
let mockRemoteConfigClient = MockRemoteConfigClient()
|> \.features .~ [
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: false
RemoteConfigFeature.blockUsersEnabled.rawValue: false
]

withEnvironment(remoteConfigClient: mockRemoteConfigClient, userDefaults: userDefaults) {
Expand All @@ -117,7 +119,7 @@ final class RemoteConfigFlagToolsViewModelTests: TestCase {
userDefaults
.dictionary(forKey: "com.kickstarter.KeyValueStoreType.remoteConfigFeatureFlags") as? [String: Bool],
[
RemoteConfigFeature.consentManagementDialogEnabled.rawValue: true
RemoteConfigFeature.blockUsersEnabled.rawValue: true
]
)
}
Expand Down

0 comments on commit 11adbfc

Please sign in to comment.