Skip to content

Commit 2d7dfa9

Browse files
nan-licursoragent
andcommitted
chore: [PR8] add local feature-flag override for testing
Mirror Android FeatureManager.localFeatureOverrides so testers can force sdk_identity_verification on without waiting on remote config. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1fbdef9 commit 2d7dfa9

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSFeatureManager.swift‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,33 @@ public final class OSFeatureManager: OSFeatureManagerProtocol {
4848
/// deliver flag keys. Everything below them is handed the feature manager when it is created.
4949
public static let shared = OSFeatureManager()
5050

51+
/**
52+
Local-only test hook for forcing features ON without backend config.
53+
Add keys here while testing locally, e.g. `[OSFeatureFlag.identityVerification.rawValue]`.
54+
*/
55+
private static let localFeatureOverrides: Set<String> = []
56+
// private static let localFeatureOverrides: Set<String> = [
57+
// OSFeatureFlag.identityVerification.rawValue
58+
// ]
59+
5160
private let lock = NSLock()
5261
private var enabledKeys: Set<String>
5362

5463
public init() {
5564
enabledKeys = OSFeatureManager.cachedKeys()
65+
OSFeatureManager.warnIfLocalOverrides()
5666
}
5767

5868
/// Bypasses the cache so tests can force flags on.
5969
public init(enabledKeys: Set<String>) {
6070
self.enabledKeys = Set(enabledKeys.map(OSFeatureManager.canonicalize))
71+
OSFeatureManager.warnIfLocalOverrides()
6172
}
6273

6374
public func isEnabled(_ feature: OSFeatureFlag) -> Bool {
6475
return lock.withLock {
6576
enabledKeys.contains(feature.rawValue)
77+
|| OSFeatureManager.localFeatureOverrides.contains(feature.rawValue)
6678
}
6779
}
6880

@@ -99,4 +111,15 @@ public final class OSFeatureManager: OSFeatureManagerProtocol {
99111
}
100112
return Set(cached.map(canonicalize))
101113
}
114+
115+
private static func warnIfLocalOverrides() {
116+
let overrides = Set(localFeatureOverrides.map(canonicalize))
117+
guard !overrides.isEmpty else {
118+
return
119+
}
120+
OneSignalLog.onesignalLog(
121+
.LL_WARN,
122+
message: "OSFeatureManager: local feature override enabled for testing only: \(overrides)"
123+
)
124+
}
102125
}

0 commit comments

Comments
 (0)