Skip to content

Commit

Permalink
hash only exists for confidence struct
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidlazio committed Apr 17, 2024
1 parent d6e45c0 commit 65da6ea
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 103 deletions.
6 changes: 5 additions & 1 deletion Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ public class ConfidenceFeatureProvider: FeatureProvider {
oldContext: OpenFeature.EvaluationContext?,
newContext: OpenFeature.EvaluationContext
) {
guard oldContext?.hash() != newContext.hash() else {
var oldConfidenceContext: ConfidenceStruct = [:]
if let context = oldContext {
oldConfidenceContext = ConfidenceTypeMapper.from(ctx: context)
}
guard oldConfidenceContext.hash() != ConfidenceTypeMapper.from(ctx: newContext).hash() else {
return
}

Expand Down
70 changes: 0 additions & 70 deletions Sources/ConfidenceProvider/Utils/EvaluationContextHash.swift

This file was deleted.

31 changes: 0 additions & 31 deletions Tests/ConfidenceProviderTests/EvaluationContextHashTest.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/ConfidenceProviderTests/Helpers/StorageMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StorageMock: Storage {
if data.isEmpty {
return defaultValue
}
return try JSONDecoder().decode(T.self, from: data.data)
return try JSONDecoder().decode(T.self, from: try XCTUnwrap(data.data(using: .utf8)))
}
}

Expand Down
44 changes: 44 additions & 0 deletions Tests/ConfidenceTests/ConfidenceValueHashTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import XCTest

@testable import Confidence

final class MutableContextTests: XCTestCase {
func testHashRespectsTargetingKey() throws {
let ctx1: ConfidenceStruct =
["targetingKey": ConfidenceValue(string: "user1"), "structure": ConfidenceValue(structure: [:])]
let ctx2: ConfidenceStruct =
["targetingKey": ConfidenceValue(string: "user2"), "structure": ConfidenceValue(structure: [:])]

XCTAssertNotEqual(ctx1.hash(), ctx2.hash())
}

func testHashRespectsStructure() throws {
let ctx1: ConfidenceStruct =
[
"targetingKey": ConfidenceValue(string: "user1"),
"structure": ConfidenceValue(structure: ["integer": ConfidenceValue(integer: 3)])
]
let ctx2: ConfidenceStruct =
[
"targetingKey": ConfidenceValue(string: "user2"),
"structure": ConfidenceValue(structure: ["integer": ConfidenceValue(integer: 4)])
]

XCTAssertNotEqual(ctx1.hash(), ctx2.hash())
}

func testHashIsEqualForEqualContext() throws {
let ctx1: ConfidenceStruct =
[
"targetingKey": ConfidenceValue(string: "user1"),
"structure": ConfidenceValue(structure: ["integer": ConfidenceValue(integer: 3)])
]
let ctx2: ConfidenceStruct =
[
"targetingKey": ConfidenceValue(string: "user2"),
"structure": ConfidenceValue(structure: ["integer": ConfidenceValue(integer: 3)])
]

XCTAssertNotEqual(ctx1.hash(), ctx2.hash())
}
}

0 comments on commit 65da6ea

Please sign in to comment.