diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index f9847b87..e0006979 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -51,11 +51,6 @@ public class Confidence: ConfidenceEventSender { removedContextKeys.insert(key) } - public func clearContext() { - removedContextKeys.removeAll() - context = [:] - } - public func withContext(_ context: ConfidenceStruct) -> Self { return Self.init( clientSecret: clientSecret, diff --git a/Sources/Confidence/Contextual.swift b/Sources/Confidence/Contextual.swift index 3f15b1e4..554babd5 100644 --- a/Sources/Confidence/Contextual.swift +++ b/Sources/Confidence/Contextual.swift @@ -4,13 +4,11 @@ import Foundation /// that can still access their parent's data /// Each ConfidenceContextProvider returns local data reconciled with parents' data. Local data has precedence public protocol Contextual: ConfidenceContextProvider { - /// Adds entry to local data + /// Adds/override entry to local data func updateContextEntry(key: String, value: ConfidenceValue) /// Removes entry from local data /// It hides entries with this key from parents' data (without modifying parents' data) func removeContextEntry(key: String) - /// Clear local data. Parents' data is still reconciled. Previously removed parent entries are not hidden anymore - func clearContext() /// Creates a child Contextual instance that maintains access to its parent's data func withContext(_ context: ConfidenceStruct) -> Self } diff --git a/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift b/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift index 3183a877..759d2bda 100644 --- a/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift +++ b/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift @@ -936,7 +936,9 @@ class ConfidenceFeatureProviderTest: XCTestCase { }) { let ctx1 = MutableContext(targetingKey: "user1") - let ctx2 = MutableContext(targetingKey: "user1", structure: MutableStructure(attributes: ["active": Value.boolean(true)])) + let ctx2 = MutableContext( + targetingKey: "user1", + structure: MutableStructure(attributes: ["active": Value.boolean(true)])) provider.initialize(initialContext: ctx1) provider.onContextSet(oldContext: ctx1, newContext: ctx2) wait(for: [readyExpectation], timeout: 5) diff --git a/Tests/ConfidenceTests/ConfidenceTests.swift b/Tests/ConfidenceTests/ConfidenceTests.swift index 8403ae40..b77e05a5 100644 --- a/Tests/ConfidenceTests/ConfidenceTests.swift +++ b/Tests/ConfidenceTests/ConfidenceTests.swift @@ -180,41 +180,4 @@ final class ConfidenceTests: XCTestCase { ] XCTAssertEqual(confidenceChild.getContext(), expected) } - - func testClearContext() { - let confidence = Confidence.init( - clientSecret: "", - timeout: TimeInterval(), - region: .europe, - initializationStrategy: .activateAndFetchAsync, - context: [ - "k1": ConfidenceValue(string: "v1"), - "k2": ConfidenceValue(string: "v2") - ] - ) - confidence.clearContext() - let expected: ConfidenceStruct = [:] - XCTAssertEqual(confidence.getContext(), expected) - } - - func testClearContextReturnsParentContext() { - let confidenceParent = Confidence.init( - clientSecret: "", - timeout: TimeInterval(), - region: .europe, - initializationStrategy: .activateAndFetchAsync, - context: ["k1": ConfidenceValue(string: "v1")] - ) - let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( - [ - "k1": ConfidenceValue(string: "v1"), - "k2": ConfidenceValue(string: "v2") - ] - ) - confidenceChild.clearContext() - let expected = [ - "k1": ConfidenceValue(string: "v1") - ] - XCTAssertEqual(confidenceChild.getContext(), expected) - } }