Skip to content
Draft
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
14 changes: 7 additions & 7 deletions packages/core/DatadogSDKReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ Pod::Spec.new do |s|
s.dependency "React-Core"

# /!\ Remember to keep the versions in sync with DatadogSDKReactNativeSessionReplay.podspec
s.dependency 'DatadogCore', '3.16.0'
s.dependency 'DatadogLogs', '3.16.0'
s.dependency 'DatadogTrace', '3.16.0'
s.dependency 'DatadogRUM', '3.16.0'
s.dependency 'DatadogCrashReporting', '3.16.0'
s.dependency 'DatadogFlags', '3.16.0'
s.dependency 'DatadogCore', '3.17.0'
s.dependency 'DatadogLogs', '3.17.0'
s.dependency 'DatadogTrace', '3.17.0'
s.dependency 'DatadogRUM', '3.17.0'
s.dependency 'DatadogCrashReporting', '3.17.0'
s.dependency 'DatadogFlags', '3.17.0'

# DatadogWebViewTracking is not available for tvOS
s.ios.dependency 'DatadogWebViewTracking', '3.16.0'
s.ios.dependency 'DatadogWebViewTracking', '3.17.0'

s.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'ios/Tests/**/*.{swift,json}'
Expand Down
13 changes: 11 additions & 2 deletions packages/core/ios/Sources/DdFlagsImplementation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extension FlagAssignment {
case .unknown: NSNull()
}

return [
var dictionary: [String: Any] = [
"key": flagKey,
"value": value,
"allocationKey": allocationKey,
Expand All @@ -184,9 +184,17 @@ extension FlagAssignment {
"variationValue": "",
"extraLogging": [:],
]

if let serialID {
dictionary[serialIDKey] = String(serialID)
}

return dictionary
}
}

private let serialIDKey = "serialId"

extension NSDictionary {
func asFlagAssignment() -> FlagAssignment? {
guard
Expand All @@ -213,7 +221,8 @@ extension NSDictionary {
variationKey: variationKey,
variation: variation,
reason: reason,
doLog: doLog
doLog: doLog,
serialID: (object(forKey: serialIDKey) as? String).flatMap(Int.init)
)
}
}
Expand Down
99 changes: 99 additions & 0 deletions packages/core/ios/Tests/DdFlagsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,40 @@ class DdFlagsTests: XCTestCase {
XCTAssertEqual(dict["variationType"] as? String, "")
XCTAssertEqual(dict["variationValue"] as? String, "")
XCTAssertNotNil(dict["extraLogging"] as? [String: Any])
// An assignment with no serial ID omits the key rather than sending NSNull.
XCTAssertNil(dict["serialId"])
}

func testFlagAssignmentToDictionaryCarriesSerialID() {
let assignment = FlagAssignment(
allocationKey: "alloc",
variationKey: "var",
variation: .boolean(true),
reason: "reason",
doLog: true,
serialID: 340132
)

let dict = assignment.asDictionary(flagKey: "flag1")

// Sent as a String because the React Native bridge converts integers to Double.
XCTAssertEqual(dict["serialId"] as? String, "340132")
}

func testFlagAssignmentToDictionaryCarriesSerialIDZero() {
// Serial IDs are zero-based per org, so 0 is a real value, not an absent one.
let assignment = FlagAssignment(
allocationKey: "alloc",
variationKey: "var",
variation: .boolean(true),
reason: "reason",
doLog: true,
serialID: 0
)

let dict = assignment.asDictionary(flagKey: "flag1")

XCTAssertEqual(dict["serialId"] as? String, "0")
}

func testDictionaryToFlagAssignment() {
Expand All @@ -389,6 +423,71 @@ class DdFlagsTests: XCTestCase {
} else {
XCTFail("Expected string variation")
}
XCTAssertNil(assignment?.serialID)
}

func testDictionaryToFlagAssignmentReadsSerialID() {
let dict: NSDictionary = [
"allocationKey": "alloc",
"variationKey": "var",
"reason": "reason",
"doLog": true,
"value": "string_value",
"serialId": "340132"
]

XCTAssertEqual(dict.asFlagAssignment()?.serialID, 340132)
}

func testDictionaryToFlagAssignmentReadsSerialIDZero() {
let dict: NSDictionary = [
"allocationKey": "alloc",
"variationKey": "var",
"reason": "reason",
"doLog": true,
"value": "string_value",
"serialId": "0"
]

XCTAssertEqual(dict.asFlagAssignment()?.serialID, 0)
}

func testDictionaryToFlagAssignmentIgnoresMalformedSerialID() {
// A malformed serial ID binds to the serial ID. It must not reject the assignment,
// because that would drop the exposure event for the whole flag.
let malformedValues: [Any] = ["not-a-number", "", true, 340132]

for malformed in malformedValues {
let dict: NSDictionary = [
"allocationKey": "alloc",
"variationKey": "var",
"reason": "reason",
"doLog": true,
"value": "string_value",
"serialId": malformed
]

let assignment = dict.asFlagAssignment()

XCTAssertNotNil(assignment, "Expected an assignment for serialId \(malformed)")
XCTAssertNil(assignment?.serialID, "Expected no serial ID for \(malformed)")
}
}

func testFlagAssignmentSerialIDSurvivesARoundTrip() {
let assignment = FlagAssignment(
allocationKey: "alloc",
variationKey: "var",
variation: .string("string_value"),
reason: "reason",
doLog: true,
serialID: 0
)

let roundTripped = (assignment.asDictionary(flagKey: "flag1") as NSDictionary)
.asFlagAssignment()

XCTAssertEqual(roundTripped?.serialID, 0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Pod::Spec.new do |s|
s.dependency "React-Core"

# /!\ Remember to keep the version in sync with DatadogSDKReactNative.podspec
s.dependency 'DatadogSessionReplay', '3.16.0'
s.dependency 'DatadogSessionReplay', '3.17.0'
s.dependency 'DatadogSDKReactNative'

s.test_spec 'Tests' do |test_spec|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Pod::Spec.new do |s|
end

# /!\ Remember to keep the version in sync with DatadogSDKReactNative.podspec
s.dependency 'DatadogWebViewTracking', '3.16.0'
s.dependency 'DatadogInternal', '3.16.0'
s.dependency 'DatadogWebViewTracking', '3.17.0'
s.dependency 'DatadogInternal', '3.17.0'
s.dependency 'DatadogSDKReactNative'

s.test_spec 'Tests' do |test_spec|
Expand Down