Skip to content

Commit c747f79

Browse files
authored
feat: default session id (#122)
1 parent 3c5ed9c commit c747f79

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Sources/UnleashProxyClientSwift/Client/UnleashProxyClientSwift.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class UnleashClientBase {
6262
self.metrics = Metrics(appName: appName, metricsInterval: Double(metricsInterval), clock: { return Date() }, disableMetrics: disableMetrics, poster: urlSessionPoster, url: url, clientKey: clientKey, customHeaders: customHeaders, connectionId: connectionId)
6363
}
6464

65-
self.context = Context(appName: appName, environment: environment)
65+
self.context = Context(appName: appName, environment: environment, sessionId: String(Int.random(in: 0..<1_000_000_000)))
6666
if let providedContext = context {
6767
self.context = self.calculateContext(context: providedContext)
6868
}
@@ -192,12 +192,14 @@ public class UnleashClientBase {
192192
properties?.forEach { (key, value) in
193193
newProperties[key] = value
194194
}
195+
196+
let sessionId = context["sessionId"] ?? self.context.sessionId;
195197

196198
let newContext = Context(
197199
appName: self.context.appName,
198200
environment: self.context.environment,
199201
userId: context["userId"],
200-
sessionId: context["sessionId"],
202+
sessionId: sessionId,
201203
remoteAddress: context["remoteAddress"],
202204
properties: newProperties
203205
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
public struct LibraryInfo {
2-
public static let version = "2.1.0" // Update this string with each new release
2+
public static let version = "2.2.0" // Update this string with each new release
33
}

Tests/UnleashProxyClientSwiftTests/UnleashClientIntegrationTest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class UnleashIntegrationTests: XCTestCase {
1212
clientKey: "SDKIntegration:development.f0474f4a37e60794ee8fb00a4c112de58befde962af6d5055b383ea3",
1313
refreshInterval: 15,
1414
appName: "testIntegration",
15-
context: ["clientId": "disabled"]
15+
context: ["clientId": "disabled", "sessionId": "1234"]
1616
)
1717
}
1818

@@ -23,7 +23,7 @@ class UnleashIntegrationTests: XCTestCase {
2323
func testUserJourneyHappyPath() {
2424
let expectation = self.expectation(description: "Waiting for client updates")
2525

26-
XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration"])
26+
XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration", "sessionId": "1234"])
2727

2828
unleashClient.subscribe(name: "ready", callback: {
2929
XCTAssertFalse(self.unleashClient.isEnabled(name: self.featureName), "Feature should be disabled")
@@ -59,7 +59,7 @@ class UnleashIntegrationTests: XCTestCase {
5959
func testUserJourneyHappyPathWithUnleashEvent() {
6060
let expectation = self.expectation(description: "Waiting for client updates")
6161

62-
XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration"])
62+
XCTAssertEqual(unleashClient.context.toMap(), ["environment": "default", "clientId": "disabled", "appName": "testIntegration", "sessionId": "1234"])
6363

6464
unleashClient.subscribe(.ready) {
6565
XCTAssertFalse(self.unleashClient.isEnabled(name: self.featureName), "Feature should be disabled")

0 commit comments

Comments
 (0)