From e78344d1ded3254dd3edb9e9f6930c878f8d8bde Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Fri, 3 May 2024 08:53:57 +0200 Subject: [PATCH] fix: Visitor id key (#116) fix: Visitor Id context key --- Sources/Confidence/Confidence.swift | 2 +- Tests/ConfidenceTests/ConfidenceTests.swift | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 93ca47f5..475eeeed 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -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)]) } } diff --git a/Tests/ConfidenceTests/ConfidenceTests.swift b/Tests/ConfidenceTests/ConfidenceTests.swift index 844f9064..7cee4174 100644 --- a/Tests/ConfidenceTests/ConfidenceTests.swift +++ b/Tests/ConfidenceTests/ConfidenceTests.swift @@ -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) } @@ -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) @@ -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"]) } }