Skip to content

Commit

Permalink
vuid_optln: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
muzahidul-opti committed Nov 25, 2024
1 parent 2066d0f commit 509d3ac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Sources/ODP/OdpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public class OdpManager {
completionHandler: completionHandler)
}

func sendInitializedEvent(vuid: String) throws {
guard enabled else { throw OptimizelyError.odpNotEnabled }
guard odpConfig.eventQueueingAllowed else { throw OptimizelyError.odpNotIntegrated }
eventManager.sendInitializedEvent(vuid: vuid)
}

func identifyUser(userId: String) {
guard enabled else {
logger.d("ODP identify event is not dispatched (ODP disabled).")
Expand Down
12 changes: 5 additions & 7 deletions Sources/Optimizely/OptimizelyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ open class OptimizelyClient: NSObject {
self.notificationCenter = HandlerRegistryService.shared.injectNotificationCenter(sdkKey: self.sdkKey)
if let _vuid = vuid {
self.odpManager.vuid = _vuid
try? sendOdpEvent(type: Constants.ODP.eventType,
action: "client_initialized",
identifiers: [
Constants.ODP.keyForVuid: _vuid
],
data: [:])

sendInitializedEvent(vuid: _vuid)
}
logger.d("SDK Version: \(version)")
}
Expand Down Expand Up @@ -984,6 +978,10 @@ extension OptimizelyClient {
data: data)
}

func sendInitializedEvent(vuid: String) {
try? odpManager.sendInitializedEvent(vuid: vuid)
}

func identifyUserToOdp(userId: String) {
odpManager.identifyUser(userId: userId)
}
Expand Down
21 changes: 18 additions & 3 deletions Tests/OptimizelyTests-APIs/OptimizelyClientTests_ODP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,24 @@ class OptimizelyClientTests_ODP: XCTestCase {
XCTAssert(optimizely.vuid!.starts(with: "vuid_"))
}

func testVuidDiabled() {
// Default client vuid diabled
XCTAssertNil(optimizely.vuid)
func test_register_vuid_autometically_when_enabled() {
let settings = OptimizelySdkSettings(enableVuid: true)
optimizely = OptimizelyClient(sdkKey: OTUtils.randomSdkKey, settings: settings)
let eventManager = optimizely.odpManager.eventManager!
let evt = eventManager.eventQueue.getFirstItem()!

XCTAssertEqual("fullstack", evt.type)
XCTAssertEqual("client_initialized", evt.action)
XCTAssertEqual(["vuid": optimizely.vuid], evt.identifiers)
XCTAssertNotNil(optimizely.vuid)
}

func test_vuid_does_not_register_autometically_when_enabled_but_odp_disabled() {
let settings = OptimizelySdkSettings(disableOdp: true, enableVuid: true)
optimizely = OptimizelyClient(sdkKey: OTUtils.randomSdkKey, settings: settings)
XCTAssertNotNil(optimizely.vuid)
let eventManager = optimizely.odpManager.eventManager
XCTAssertNil(eventManager)
}

// MARK: - OdpConfig Update
Expand Down

0 comments on commit 509d3ac

Please sign in to comment.