From 873e6b722eb94b1c463cef4d0bb62428fdbcfedb Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Tue, 28 May 2024 11:01:36 +0200 Subject: [PATCH] refactor: visitor id is default (#129) --- Sources/Confidence/Confidence.swift | 11 +---------- Tests/ConfidenceTests/ConfidenceTests.swift | 11 ----------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 7b688cd0..c7c28c5b 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -231,7 +231,7 @@ extension Confidence { internal var flagResolver: ConfidenceResolveClient? var region: ConfidenceRegion = .global - var visitorId: String? + var visitorId = VisitorUtil().getId() var initialContext: ConfidenceStruct = [:] /** @@ -276,15 +276,6 @@ extension Confidence { return self } - /** - The SDK attaches a unique identifier to the Context, which is persisted across - restarts of the App but re-generated on every new install - */ - public func withVisitorId() -> Builder { - self.visitorId = VisitorUtil().getId() - return self - } - public func build() -> Confidence { let options = ConfidenceClientOptions( credentials: ConfidenceClientCredentials.clientSecret(secret: clientSecret), diff --git a/Tests/ConfidenceTests/ConfidenceTests.swift b/Tests/ConfidenceTests/ConfidenceTests.swift index 61a951be..1aec5d6f 100644 --- a/Tests/ConfidenceTests/ConfidenceTests.swift +++ b/Tests/ConfidenceTests/ConfidenceTests.swift @@ -288,31 +288,20 @@ final class ConfidenceTests: XCTestCase { let userDefaults = UserDefaults.standard userDefaults.removeObject(forKey: "confidence.visitor_id") let confidence = Confidence.Builder(clientSecret: "") - .withVisitorId() .build() 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()["visitor_id"]?.asString())) userDefaults.removeObject(forKey: "confidence.visitor_id") let veryNewConfidence = Confidence.Builder(clientSecret: "") - .withVisitorId() .build() let newVisitorId = try XCTUnwrap(veryNewConfidence.getContext()["visitor_id"]?.asString()) XCTAssertNotEqual(newVisitorId, "") XCTAssertNotEqual(newVisitorId, "storage-error") XCTAssertNotEqual(newVisitorId, visitorId) } - - func testWithoutVisitorId() throws { - let userDefaults = UserDefaults.standard - userDefaults.removeObject(forKey: "confidence.visitor_id") - let confidence = Confidence.Builder(clientSecret: "") - .build() - XCTAssertNil(confidence.getContext()["visitor_id"]) - } } // swiftlint:enable type_body_length