Skip to content

Commit

Permalink
Remove clear from Contextual
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Apr 9, 2024
1 parent babc07f commit 5cb9651
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 46 deletions.
5 changes: 0 additions & 5 deletions Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions Sources/Confidence/Contextual.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 0 additions & 37 deletions Tests/ConfidenceTests/ConfidenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 5cb9651

Please sign in to comment.