Skip to content

Commit

Permalink
fix: Visitor id key (#116)
Browse files Browse the repository at this point in the history
fix: Visitor Id context key
  • Loading branch information
fabriziodemaria authored May 3, 2024
1 parent 01dda08 commit e78344d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Confidence: ConfidenceEventSender {
self.contextFlow.value = context
self.parent = parent
if let visitorId {
putContext(context: ["visitorId": ConfidenceValue.init(string: visitorId)])
putContext(context: ["visitor_id": ConfidenceValue.init(string: visitorId)])
}
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/ConfidenceTests/ConfidenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ final class ConfidenceTests: XCTestCase {
)
let expected = [
"k1": ConfidenceValue(string: "v1"),
"visitorId": ConfidenceValue(string: "uuid")
"visitor_id": ConfidenceValue(string: "uuid")
]
XCTAssertEqual(confidence.getContext(), expected)
}
Expand All @@ -234,18 +234,18 @@ final class ConfidenceTests: XCTestCase {
let confidence = Confidence.Builder(clientSecret: "")
.withVisitorId()
.build()
let visitorId = try XCTUnwrap(confidence.getContext()["visitorId"]?.asString())
let visitorId = try XCTUnwrap(confidence.getContext()["visitor_id"]?.asString())
XCTAssertNotEqual(visitorId, "")
XCTAssertNotEqual(visitorId, "storage-error")
let newConfidence = Confidence.Builder(clientSecret: "")
.withVisitorId()
.build()
XCTAssertEqual(visitorId, try XCTUnwrap(newConfidence.getContext()["visitorId"]?.asString()))
XCTAssertEqual(visitorId, try XCTUnwrap(newConfidence.getContext()["visitor_id"]?.asString()))
userDefaults.removeObject(forKey: "confidence.visitor_id")
let veryNewConfidence = Confidence.Builder(clientSecret: "")
.withVisitorId()
.build()
let newVisitorId = try XCTUnwrap(veryNewConfidence.getContext()["visitorId"]?.asString())
let newVisitorId = try XCTUnwrap(veryNewConfidence.getContext()["visitor_id"]?.asString())
XCTAssertNotEqual(newVisitorId, "")
XCTAssertNotEqual(newVisitorId, "storage-error")
XCTAssertNotEqual(newVisitorId, visitorId)
Expand All @@ -256,6 +256,6 @@ final class ConfidenceTests: XCTestCase {
userDefaults.removeObject(forKey: "confidence.visitor_id")
let confidence = Confidence.Builder(clientSecret: "")
.build()
XCTAssertNil(confidence.getContext()["visitorId"])
XCTAssertNil(confidence.getContext()["visitor_id"])
}
}

0 comments on commit e78344d

Please sign in to comment.