Skip to content

Commit

Permalink
refactor: visitor id is default (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria authored May 28, 2024
1 parent 91604eb commit 873e6b7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
11 changes: 1 addition & 10 deletions Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ extension Confidence {
internal var flagResolver: ConfidenceResolveClient?
var region: ConfidenceRegion = .global

var visitorId: String?
var visitorId = VisitorUtil().getId()
var initialContext: ConfidenceStruct = [:]

/**
Expand Down Expand Up @@ -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),
Expand Down
11 changes: 0 additions & 11 deletions Tests/ConfidenceTests/ConfidenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 873e6b7

Please sign in to comment.