From c63f7855e1078f2be7a09e4bc7ac9f606e30aa64 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 9 Apr 2024 09:22:05 +0200 Subject: [PATCH 1/4] Implement withContext --- Sources/Confidence/Confidence.swift | 40 ++++-- Tests/ConfidenceTests/ConfidenceTests.swift | 137 ++++++++++++++++++++ 2 files changed, 168 insertions(+), 9 deletions(-) create mode 100644 Tests/ConfidenceTests/ConfidenceTests.swift diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 09d8208c..48f4bb0e 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -1,23 +1,40 @@ import Foundation public class Confidence: ConfidenceEventSender { - public var context: ConfidenceStruct + private let parent: ConfidenceEventSender? + private var localContext: ConfidenceStruct + + public var context: ConfidenceStruct { + get { + var mergedContext = parent?.context ?? [:] + localContext.forEach { entry in + mergedContext.updateValue(entry.value, forKey: entry.key) + } + return mergedContext + } + set { + self.localContext = newValue + } + } public let clientSecret: String public var timeout: TimeInterval public var region: ConfidenceRegion public var initializationStrategy: InitializationStrategy - init( + required public init( clientSecret: String, timeout: TimeInterval, region: ConfidenceRegion, - initializationStrategy: InitializationStrategy + initializationStrategy: InitializationStrategy, + context: ConfidenceStruct = [:], + parent: ConfidenceEventSender? = nil ) { - self.context = [:] self.clientSecret = clientSecret self.timeout = timeout self.region = region self.initializationStrategy = initializationStrategy + self.localContext = context + self.parent = parent } // TODO: Implement actual event uploading to the backend @@ -26,20 +43,25 @@ public class Confidence: ConfidenceEventSender { } public func updateContextEntry(key: String, value: ConfidenceValue) { - context[key] = value + localContext[key] = value } public func removeContextEntry(key: String) { - context.removeValue(forKey: key) + localContext.removeValue(forKey: key) } public func clearContext() { - context = [:] + localContext = [:] } - // TODO: Implement creation of child instances public func withContext(_ context: ConfidenceStruct) -> Self { - return self + return Self.init( + clientSecret: clientSecret, + timeout: timeout, + region: region, + initializationStrategy: initializationStrategy, + context: context, + parent: self) } } diff --git a/Tests/ConfidenceTests/ConfidenceTests.swift b/Tests/ConfidenceTests/ConfidenceTests.swift new file mode 100644 index 00000000..0262d42f --- /dev/null +++ b/Tests/ConfidenceTests/ConfidenceTests.swift @@ -0,0 +1,137 @@ +import Confidence +import XCTest + +final class ConfidenceTests: XCTestCase { + func testWithContext() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + ["k2": ConfidenceValue(string: "v2")] + ) + let expected = [ + "k1": ConfidenceValue(string: "v1"), + "k2": ConfidenceValue(string: "v2") + ] + XCTAssertEqual(confidenceChild.context, expected) + } + + func testWithContextUpdateParent() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + ["k2": ConfidenceValue(string: "v2")] + ) + confidenceParent.updateContextEntry( + key: "k3", + value: ConfidenceValue(string: "v3")) + let expected = [ + "k1": ConfidenceValue(string: "v1"), + "k2": ConfidenceValue(string: "v2"), + "k3": ConfidenceValue(string: "v3"), + ] + XCTAssertEqual(confidenceChild.context, expected) + } + + func testUpdateContextWithOverride() { + let confidence = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + confidence.updateContextEntry( + key: "k1", + value: ConfidenceValue(string: "v3")) + let expected = [ + "k1": ConfidenceValue(string: "v3"), + ] + XCTAssertEqual(confidence.context, expected) + } + + func testWithContextUpdateParentWithoutOverride() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + ["k2": ConfidenceValue(string: "v2")] + ) + confidenceParent.updateContextEntry( + key: "k2", + value: ConfidenceValue(string: "v4")) + let expected = [ + "k1": ConfidenceValue(string: "v1"), + "k2": ConfidenceValue(string: "v2"), + ] + XCTAssertEqual(confidenceChild.context, expected) + } + + func testWithContextUpdateChildWithOverride() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + ["k2": ConfidenceValue(string: "v2")] + ) + confidenceChild.updateContextEntry( + key: "k2", + value: ConfidenceValue(string: "v4")) + let expected = [ + "k1": ConfidenceValue(string: "v1"), + "k2": ConfidenceValue(string: "v4"), + ] + XCTAssertEqual(confidenceChild.context, expected) + } + + func testRemoveContextEntry() { + let confidence = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: [ + "k1": ConfidenceValue(string: "v1"), + "k2": ConfidenceValue(string: "v2") + ] + ) + confidence.removeContextEntry(key: "k2") + let expected = [ + "k1": ConfidenceValue(string: "v1") + ] + XCTAssertEqual(confidence.context, 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.context, expected) + } +} From a331d76e3d3bc26fdc958cc0f1ea7575b4f3f532 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 9 Apr 2024 14:23:29 +0200 Subject: [PATCH 2/4] Add ConfidenceContextProvider protocol --- Sources/Confidence/Confidence.swift | 34 ++++++++----------- .../ConfidenceContextProvider.swift | 6 ++++ Sources/Confidence/Contextual.swift | 4 +-- Tests/ConfidenceTests/ConfidenceTests.swift | 14 ++++---- 4 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 Sources/Confidence/ConfidenceContextProvider.swift diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 48f4bb0e..58c23a77 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -1,21 +1,8 @@ import Foundation public class Confidence: ConfidenceEventSender { - private let parent: ConfidenceEventSender? - private var localContext: ConfidenceStruct - - public var context: ConfidenceStruct { - get { - var mergedContext = parent?.context ?? [:] - localContext.forEach { entry in - mergedContext.updateValue(entry.value, forKey: entry.key) - } - return mergedContext - } - set { - self.localContext = newValue - } - } + private let parent: ConfidenceContextProvider? + private var context: ConfidenceStruct public let clientSecret: String public var timeout: TimeInterval public var region: ConfidenceRegion @@ -33,7 +20,7 @@ public class Confidence: ConfidenceEventSender { self.timeout = timeout self.region = region self.initializationStrategy = initializationStrategy - self.localContext = context + self.context = context self.parent = parent } @@ -42,16 +29,25 @@ public class Confidence: ConfidenceEventSender { print("Sending: \"\(definition)\".\nMessage: \(payload)\nContext: \(context)") } + + public func getContext() -> ConfidenceStruct { + var mergedContext = parent?.getContext() ?? [:] + self.context.forEach { entry in + mergedContext.updateValue(entry.value, forKey: entry.key) + } + return mergedContext + } + public func updateContextEntry(key: String, value: ConfidenceValue) { - localContext[key] = value + context[key] = value } public func removeContextEntry(key: String) { - localContext.removeValue(forKey: key) + context.removeValue(forKey: key) } public func clearContext() { - localContext = [:] + context = [:] } public func withContext(_ context: ConfidenceStruct) -> Self { diff --git a/Sources/Confidence/ConfidenceContextProvider.swift b/Sources/Confidence/ConfidenceContextProvider.swift new file mode 100644 index 00000000..b9e5424a --- /dev/null +++ b/Sources/Confidence/ConfidenceContextProvider.swift @@ -0,0 +1,6 @@ +import Foundation + +/// A Contextual implementer returns the current context +public protocol ConfidenceContextProvider { + func getContext() -> ConfidenceStruct +} diff --git a/Sources/Confidence/Contextual.swift b/Sources/Confidence/Contextual.swift index 390279a6..0199ad89 100644 --- a/Sources/Confidence/Contextual.swift +++ b/Sources/Confidence/Contextual.swift @@ -2,9 +2,7 @@ import Foundation /// A Contextual implementer maintains context data and can create child instances /// that can still access their parent's data -public protocol Contextual { - var context: ConfidenceStruct { get set } - +public protocol Contextual: ConfidenceContextProvider { func updateContextEntry(key: String, value: ConfidenceValue) func removeContextEntry(key: String) func clearContext() diff --git a/Tests/ConfidenceTests/ConfidenceTests.swift b/Tests/ConfidenceTests/ConfidenceTests.swift index 0262d42f..94596ef8 100644 --- a/Tests/ConfidenceTests/ConfidenceTests.swift +++ b/Tests/ConfidenceTests/ConfidenceTests.swift @@ -17,7 +17,7 @@ final class ConfidenceTests: XCTestCase { "k1": ConfidenceValue(string: "v1"), "k2": ConfidenceValue(string: "v2") ] - XCTAssertEqual(confidenceChild.context, expected) + XCTAssertEqual(confidenceChild.getContext(), expected) } func testWithContextUpdateParent() { @@ -39,7 +39,7 @@ final class ConfidenceTests: XCTestCase { "k2": ConfidenceValue(string: "v2"), "k3": ConfidenceValue(string: "v3"), ] - XCTAssertEqual(confidenceChild.context, expected) + XCTAssertEqual(confidenceChild.getContext(), expected) } func testUpdateContextWithOverride() { @@ -56,7 +56,7 @@ final class ConfidenceTests: XCTestCase { let expected = [ "k1": ConfidenceValue(string: "v3"), ] - XCTAssertEqual(confidence.context, expected) + XCTAssertEqual(confidence.getContext(), expected) } func testWithContextUpdateParentWithoutOverride() { @@ -77,7 +77,7 @@ final class ConfidenceTests: XCTestCase { "k1": ConfidenceValue(string: "v1"), "k2": ConfidenceValue(string: "v2"), ] - XCTAssertEqual(confidenceChild.context, expected) + XCTAssertEqual(confidenceChild.getContext(), expected) } func testWithContextUpdateChildWithOverride() { @@ -98,7 +98,7 @@ final class ConfidenceTests: XCTestCase { "k1": ConfidenceValue(string: "v1"), "k2": ConfidenceValue(string: "v4"), ] - XCTAssertEqual(confidenceChild.context, expected) + XCTAssertEqual(confidenceChild.getContext(), expected) } func testRemoveContextEntry() { @@ -116,7 +116,7 @@ final class ConfidenceTests: XCTestCase { let expected = [ "k1": ConfidenceValue(string: "v1") ] - XCTAssertEqual(confidence.context, expected) + XCTAssertEqual(confidence.getContext(), expected) } func testClearContext() { @@ -132,6 +132,6 @@ final class ConfidenceTests: XCTestCase { ) confidence.clearContext() let expected: ConfidenceStruct = [:] - XCTAssertEqual(confidence.context, expected) + XCTAssertEqual(confidence.getContext(), expected) } } From babc07f49d188cbd151b77d3909190f238095138 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 9 Apr 2024 15:30:00 +0200 Subject: [PATCH 3/4] Remove context on child instance --- Sources/Confidence/Confidence.swift | 12 ++- Sources/Confidence/Contextual.swift | 10 +- .../ConfidenceFeatureProviderTest.swift | 4 +- Tests/ConfidenceTests/ConfidenceTests.swift | 97 +++++++++++++++++-- 4 files changed, 108 insertions(+), 15 deletions(-) diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 58c23a77..f9847b87 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -7,6 +7,7 @@ public class Confidence: ConfidenceEventSender { public var timeout: TimeInterval public var region: ConfidenceRegion public var initializationStrategy: InitializationStrategy + private var removedContextKeys: Set = Set() required public init( clientSecret: String, @@ -31,11 +32,14 @@ public class Confidence: ConfidenceEventSender { public func getContext() -> ConfidenceStruct { - var mergedContext = parent?.getContext() ?? [:] + let parentContext = parent?.getContext() ?? [:] + var reconciledCtx = parentContext.filter { + !removedContextKeys.contains($0.key) + } self.context.forEach { entry in - mergedContext.updateValue(entry.value, forKey: entry.key) + reconciledCtx.updateValue(entry.value, forKey: entry.key) } - return mergedContext + return reconciledCtx } public func updateContextEntry(key: String, value: ConfidenceValue) { @@ -44,9 +48,11 @@ public class Confidence: ConfidenceEventSender { public func removeContextEntry(key: String) { context.removeValue(forKey: key) + removedContextKeys.insert(key) } public func clearContext() { + removedContextKeys.removeAll() context = [:] } diff --git a/Sources/Confidence/Contextual.swift b/Sources/Confidence/Contextual.swift index 0199ad89..3f15b1e4 100644 --- a/Sources/Confidence/Contextual.swift +++ b/Sources/Confidence/Contextual.swift @@ -1,12 +1,16 @@ import Foundation -/// A Contextual implementer maintains context data and can create child instances +/// A Contextual implementer maintains local context data and can create child instances /// 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 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 still has access - /// to its parent context + /// 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 919f71f8..3183a877 100644 --- a/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift +++ b/Tests/ConfidenceProviderTests/ConfidenceFeatureProviderTest.swift @@ -913,7 +913,7 @@ class ConfidenceFeatureProviderTest: XCTestCase { { provider.initialize(initialContext: MutableContext(targetingKey: "user1")) wait(for: [readyExpectation], timeout: 5) - let context = confidence.context + let context = confidence.getContext() let expected = [ "open_feature": ConfidenceValue(structure: ["targeting_key": ConfidenceValue(string: "user1")]) ] @@ -940,7 +940,7 @@ class ConfidenceFeatureProviderTest: XCTestCase { provider.initialize(initialContext: ctx1) provider.onContextSet(oldContext: ctx1, newContext: ctx2) wait(for: [readyExpectation], timeout: 5) - let context = confidence.context + let context = confidence.getContext() let expected = [ "open_feature": ConfidenceValue(structure: [ "targeting_key": ConfidenceValue(string: "user1"), diff --git a/Tests/ConfidenceTests/ConfidenceTests.swift b/Tests/ConfidenceTests/ConfidenceTests.swift index 94596ef8..8403ae40 100644 --- a/Tests/ConfidenceTests/ConfidenceTests.swift +++ b/Tests/ConfidenceTests/ConfidenceTests.swift @@ -42,7 +42,7 @@ final class ConfidenceTests: XCTestCase { XCTAssertEqual(confidenceChild.getContext(), expected) } - func testUpdateContextWithOverride() { + func testUpdateLocalContext() { let confidence = Confidence.init( clientSecret: "", timeout: TimeInterval(), @@ -59,7 +59,7 @@ final class ConfidenceTests: XCTestCase { XCTAssertEqual(confidence.getContext(), expected) } - func testWithContextUpdateParentWithoutOverride() { + func testUpdateLocalContextWithoutOverride() { let confidenceParent = Confidence.init( clientSecret: "", timeout: TimeInterval(), @@ -70,17 +70,17 @@ final class ConfidenceTests: XCTestCase { let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( ["k2": ConfidenceValue(string: "v2")] ) - confidenceParent.updateContextEntry( + confidenceChild.updateContextEntry( key: "k2", value: ConfidenceValue(string: "v4")) let expected = [ "k1": ConfidenceValue(string: "v1"), - "k2": ConfidenceValue(string: "v2"), + "k2": ConfidenceValue(string: "v4"), ] XCTAssertEqual(confidenceChild.getContext(), expected) } - func testWithContextUpdateChildWithOverride() { + func testUpdateParentContextWithOverride() { let confidenceParent = Confidence.init( clientSecret: "", timeout: TimeInterval(), @@ -91,12 +91,12 @@ final class ConfidenceTests: XCTestCase { let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( ["k2": ConfidenceValue(string: "v2")] ) - confidenceChild.updateContextEntry( + confidenceParent.updateContextEntry( key: "k2", value: ConfidenceValue(string: "v4")) let expected = [ "k1": ConfidenceValue(string: "v1"), - "k2": ConfidenceValue(string: "v4"), + "k2": ConfidenceValue(string: "v2"), ] XCTAssertEqual(confidenceChild.getContext(), expected) } @@ -119,6 +119,68 @@ final class ConfidenceTests: XCTestCase { XCTAssertEqual(confidence.getContext(), expected) } + func testRemoveContextEntryFromParent() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + ["k2": ConfidenceValue(string: "v2")] + ) + confidenceChild.removeContextEntry(key: "k1") + let expected = [ + "k2": ConfidenceValue(string: "v2") + ] + XCTAssertEqual(confidenceChild.getContext(), expected) + } + + func testRemoveContextEntryFromParentAndChild() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + [ + "k2": ConfidenceValue(string: "v2"), + "k1": ConfidenceValue(string: "v3"), + ] + ) + confidenceChild.removeContextEntry(key: "k1") + let expected = [ + "k2": ConfidenceValue(string: "v2") + ] + XCTAssertEqual(confidenceChild.getContext(), expected) + } + + func testRemoveContextEntryFromParentAndChildThenUpdate() { + let confidenceParent = Confidence.init( + clientSecret: "", + timeout: TimeInterval(), + region: .europe, + initializationStrategy: .activateAndFetchAsync, + context: ["k1": ConfidenceValue(string: "v1")] + ) + let confidenceChild: ConfidenceEventSender = confidenceParent.withContext( + [ + "k2": ConfidenceValue(string: "v2"), + "k1": ConfidenceValue(string: "v3"), + ] + ) + confidenceChild.removeContextEntry(key: "k1") + confidenceChild.updateContextEntry(key: "k1", value: ConfidenceValue(string: "v4")) + let expected = [ + "k2": ConfidenceValue(string: "v2"), + "k1": ConfidenceValue(string: "v4"), + ] + XCTAssertEqual(confidenceChild.getContext(), expected) + } + func testClearContext() { let confidence = Confidence.init( clientSecret: "", @@ -134,4 +196,25 @@ final class ConfidenceTests: XCTestCase { 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) + } } From 5cb9651a870fb16895894667c3aa6975725ed767 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 9 Apr 2024 16:19:58 +0200 Subject: [PATCH 4/4] Remove clear from Contextual --- Sources/Confidence/Confidence.swift | 5 --- Sources/Confidence/Contextual.swift | 4 +- .../ConfidenceFeatureProviderTest.swift | 4 +- Tests/ConfidenceTests/ConfidenceTests.swift | 37 ------------------- 4 files changed, 4 insertions(+), 46 deletions(-) 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) - } }