Skip to content

Commit

Permalink
feat: get session_id
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabmaiti committed Sep 8, 2023
1 parent bdcaa90 commit 013f9ac
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Sources/Classes/Headers/Public/RSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)startSession:(long)sessionId;
- (void)endSession;

@property (strong, nonatomic, readonly) NSNumber* _Nullable sessionId;

@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions Sources/Classes/Headers/Public/RSEventRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ NS_ASSUME_NONNULL_BEGIN

- (void) startSession:(long) sessionId;
- (void) endSession;
- (NSNumber * _Nullable)getSessionId;

- (RSConfig* _Nullable) getConfig;
- (void)applicationDidFinishLaunchingWithOptions:(NSDictionary *) launchOptions;
Expand Down
4 changes: 4 additions & 0 deletions Sources/Classes/RSClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,8 @@ - (void)endSession {
}
}

- (NSNumber * _Nullable)sessionId {
return (_repository != nil) ? [_repository getSessionId] : nil;
}

@end
3 changes: 3 additions & 0 deletions Sources/Classes/RSEventRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,8 @@ - (void) endSession {
[self->userSession clearSession];
}

- (NSNumber * _Nullable)getSessionId {
return [self->userSession getSessionId];
}

@end
2 changes: 1 addition & 1 deletion Tests/RudderUtilsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RudderUtilsTest: XCTestCase {
"company" : "RudderStack",
"city" : "Hyderabad"]

let response:Any = RSUtils.deSerializeJSONString(jsonString)
let response = RSUtils.deSerializeJSONString(jsonString)
let parsedDict:[String:String]? = response as? [String:String] ?? nil
XCTAssert(parsedDict == dictObj)

Expand Down
49 changes: 49 additions & 0 deletions Tests/UserSessionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// UserSessionTests.swift
// Rudder
//
// Created by Pallab Maiti on 06/09/23.
//

import XCTest
@testable import Rudder

final class UserSessionTests: XCTestCase {

var userSession: RSUserSession!

override func setUp() {
super.setUp()
let preferenceManager = RSPreferenceManager.getInstance()
userSession = RSUserSession.initiate(10, with: preferenceManager)
}

override func tearDown() {
super.tearDown()
}

func test_startSession() {
userSession.start()

XCTAssertEqual(userSession.getId(), RSPreferenceManager.getInstance().getSessionId())
userSession.clear()
}

func test_startSessionWithId() {
userSession.start(12345678)

XCTAssertEqual(userSession.getId(), 12345678)
XCTAssertEqual(RSPreferenceManager.getInstance().getSessionId(), 12345678)
userSession.clear()
}

func test_clearSession() {
userSession.start()

XCTAssertEqual(userSession.getId(), RSPreferenceManager.getInstance().getSessionId())
userSession.clear()

XCTAssertNil(userSession.getId())
XCTAssertNil(RSPreferenceManager.getInstance().getSessionId())
}
}

0 comments on commit 013f9ac

Please sign in to comment.