Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1197 Expose user extraInfo to Objc #444

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/DatadogObjc/Datadog+objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public class DDDatadog: NSObject {
}

@objc
public static func setUserInfo(id: String? = nil, name: String? = nil, email: String? = nil) {
Datadog.setUserInfo(id: id, name: name, email: email)
public static func setUserInfo(id: String? = nil, name: String? = nil, email: String? = nil, extraInfo: [String: Any] = [:]) {
Datadog.setUserInfo(id: id, name: name, email: email, extraInfo: castAttributesToSwift(extraInfo))
}

@objc
Expand Down
38 changes: 26 additions & 12 deletions Tests/DatadogTests/DatadogObjc/DDDatadogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import XCTest
@testable import Datadog
import DatadogObjc
@testable import DatadogObjc

/// This tests verify that objc-compatible `DatadogObjc` wrapper properly interacts with`Datadog` public API (swift).
class DDDatadogTests: XCTestCase {
Expand Down Expand Up @@ -74,17 +74,31 @@ class DDDatadogTests: XCTestCase {
trackingConsent: randomConsent().objc,
configuration: DDConfiguration.builder(clientToken: "abcefghi", environment: "tests").build()
)
let userInfo = Datadog.instance?.userInfoProvider

DDDatadog.setUserInfo(id: "id", name: "name", email: "email")
XCTAssertEqual(userInfo?.value.id, "id")
XCTAssertEqual(userInfo?.value.name, "name")
XCTAssertEqual(userInfo?.value.email, "email")

DDDatadog.setUserInfo(id: nil, name: nil, email: nil)
XCTAssertNil(userInfo?.value.id)
XCTAssertNil(userInfo?.value.name)
XCTAssertNil(userInfo?.value.email)
let userInfo = try XCTUnwrap(Datadog.instance?.userInfoProvider)

DDDatadog.setUserInfo(
id: "id",
name: "name",
email: "email",
extraInfo: [
"attribute-int": 42,
"attribute-double": 42.5,
"attribute-string": "string value"
]
)
XCTAssertEqual(userInfo.value.id, "id")
XCTAssertEqual(userInfo.value.name, "name")
XCTAssertEqual(userInfo.value.email, "email")
let extraInfo = try XCTUnwrap(userInfo.value.extraInfo as? [String: AnyEncodable])
XCTAssertEqual(extraInfo["attribute-int"]?.value as? Int, 42)
XCTAssertEqual(extraInfo["attribute-double"]?.value as? Double, 42.5)
XCTAssertEqual(extraInfo["attribute-string"]?.value as? String, "string value")

DDDatadog.setUserInfo(id: nil, name: nil, email: nil, extraInfo: [:])
XCTAssertNil(userInfo.value.id)
XCTAssertNil(userInfo.value.name)
XCTAssertNil(userInfo.value.email)
XCTAssertTrue(userInfo.value.extraInfo.isEmpty)

try Datadog.deinitializeOrThrow()
}
Expand Down
2 changes: 1 addition & 1 deletion api-surface-objc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class DDDatadog: NSObject
public static func initialize(appContext: DDAppContext,trackingConsent: DDTrackingConsent,configuration: DDConfiguration)
public static func setVerbosityLevel(_ verbosityLevel: DDSDKVerbosityLevel)
public static func verbosityLevel() -> DDSDKVerbosityLevel
public static func setUserInfo(id: String? = nil, name: String? = nil, email: String? = nil)
public static func setUserInfo(id: String? = nil, name: String? = nil, email: String? = nil, extraInfo: [String: Any] = [:])
public static func setTrackingConsent(consent: DDTrackingConsent)
public class DDEndpoint: NSObject
public static func eu() -> DDEndpoint
Expand Down