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

Updating Clickstream SDK with latest changes #11

Merged
merged 18 commits into from
May 3, 2023
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
13 changes: 9 additions & 4 deletions Clickstream.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "Clickstream"
s.version = "1.0.2"
s.version = "1.0.12"
s.summary = "Real time Analytics SDK"
s.description = "Clickstream is an event agnostic, real-time data ingestion analytics SDK"

Expand All @@ -28,21 +28,26 @@ Pod::Spec.new do |s|

s.dependency "SwiftProtobuf", "1.10.2"
s.dependency "ReachabilitySwift"
s.dependency "GRDB.swift", "5.12.0"
s.dependency "GRDB.swift", "6.7.0"
s.dependency "Starscream", "4.0.4"
s.default_subspec = 'Core'

s.subspec 'Core' do |core|
end

s.subspec 'Tracker' do |tracker|
tracker.source_files = 'Tracker/**/*.swift'
tracker.source_files = 'Sources/Tracker/**/*.swift'
tracker.xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => '$(inherited) TRACKER_ENABLED' }
end

s.subspec 'EventVisualizer' do |eventVisualizer|
eventVisualizer.source_files = 'EventVisualizer/**/*.swift'
eventVisualizer.source_files = 'Sources/EventVisualizer/**/*.swift'
eventVisualizer.xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => '$(inherited) EVENT_VISUALIZER_ENABLED' }
end

s.subspec 'ETETestSuite' do |eteTestSuite|
eteTestSuite.source_files = 'Sources/ETETestSuite/**/*.swift'
eteTestSuite.xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => '$(inherited) ETE_TEST_SUITE_ENABLED' }
end

end
646 changes: 374 additions & 272 deletions Clickstream.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

21 changes: 9 additions & 12 deletions ClickstreamTests/Core/ClickStreamDependenciesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,53 @@ import XCTest

class ClickstreamDependenciesTests: XCTestCase {

private var networkConfigurations: NetworkConfigurations!
private var dummyRequest: URLRequest!
private var constraints: ClickstreamConstraints!
private var eventClassifier: ClickstreamEventClassification!
private var prioritiesMock: [Priority]!

override func setUp() {
// given
let accessToken = "dummy_token"
let headers = ["Authorization": "Bearer \(accessToken)"]
let url = URL(string: "ws://mock.clickstream.com/events")!
self.networkConfigurations = NetworkConfigurations(baseURL: url, headers: headers)
dummyRequest = URLRequest(url: URL(string: "dummy_url")!)
self.prioritiesMock = [Priority(priority: 0, identifier: "realTime", maxBatchSize: 50000.0, maxTimeBetweenTwoBatches: 1),
Priority(priority: 1, identifier: "standard")]

self.constraints = ClickstreamConstraints(maxConnectionRetries: 15, maxConnectionRetryInterval: 5, maxRetryIntervalPostPrematureDisconnection: 10, maxRetriesPostPrematureDisconnection: 20, maxPingInterval: 15, priorities: prioritiesMock, flushOnBackground: true, connectionTerminationTimerWaitTime: 2, maxRequestAckTimeout: 3, maxRetriesPerBatch: 10, maxRetryCacheSize: 100000, connectionRetryDuration: 3)
self.constraints = ClickstreamConstraints(maxConnectionRetries: 15, maxConnectionRetryInterval: 5, maxRetryIntervalPostPrematureDisconnection: 10, maxRetriesPostPrematureDisconnection: 20, maxPingInterval: 15, priorities: prioritiesMock, flushOnBackground: true, connectionTerminationTimerWaitTime: 2, maxRequestAckTimeout: 3, maxRetriesPerBatch: 10, maxRetryCacheSize: 100000, connectionRetryDuration: 3, flushOnAppLaunch: false, minBatteryLevelPercent: 10.0)

let eventClassifierMock = ClickstreamEventClassification.EventClassifier(identifier: "ClickstreamTestRealtime", eventNames: ["CardEvent"])
self.eventClassifier = ClickstreamEventClassification(eventTypes: [eventClassifierMock])
}

override func tearDown() {
self.networkConfigurations = nil
self.dummyRequest = nil
self.prioritiesMock = nil
self.constraints = nil
self.eventClassifier = nil
}

func testNetworkBuilder() {
// when
let clickStreamDependencies = try! DefaultClickstreamDependencies(with: self.networkConfigurations)
let clickStreamDependencies = try! DefaultClickstreamDependencies(with: dummyRequest)

// then
XCTAssertNotNil(clickStreamDependencies.networkBuilder)
}

func testEventWarehouser() {
// when
let clickStreamDependencies = try! DefaultClickstreamDependencies(with: self.networkConfigurations)
let clickStreamDependencies = try! DefaultClickstreamDependencies(with: dummyRequest)

// then
XCTAssertNotNil(clickStreamDependencies.eventWarehouser)
}

func testEventProcessor() {
// given
Clickstream.constraints = MockConstants.constraints
Clickstream.eventClassifier = MockConstants.eventClassification
Clickstream.constraints = ClickstreamConstraints()
Clickstream.eventClassifier = ClickstreamEventClassification()

// when
let clickStreamDependencies = try! DefaultClickstreamDependencies(with: self.networkConfigurations)
let clickStreamDependencies = try! DefaultClickstreamDependencies(with: dummyRequest)

// then
XCTAssertNotNil(clickStreamDependencies.eventProcessor)
Expand Down
26 changes: 21 additions & 5 deletions ClickstreamTests/Core/ClickStreamTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ class ClickstreamTests: XCTestCase {

func testInitialiseClickstream() {
// when
let accessToken = "dummy_token"
let headers = ["Authorization": "Bearer \(accessToken)"]
let url = URL(string: "ws://mock.clickstream.com/events")!
let networkConfigs = NetworkConfigurations(baseURL: url, headers: headers)
let clickStream = try! Clickstream.initialise(networkConfiguration: networkConfigs, constraints: MockConstants.constraints, eventClassification: MockConstants.eventClassification)
let dummyRequest = URLRequest(url: URL(string: "dummy_url")!)
let clickStream = try! Clickstream.initialise(with: dummyRequest, configurations: ClickstreamConstraints(), eventClassification: ClickstreamEventClassification(), dataSource: self, appPrefix: "")

// then
XCTAssertNotNil(clickStream)
}

func testDataSource() {
// when
let dummyRequest = URLRequest(url: URL(string: "dummy_url")!)
let clickStream = try! Clickstream.initialise(with: dummyRequest, configurations: ClickstreamConstraints(), eventClassification: ClickstreamEventClassification(), dataSource: self, appPrefix: "")

// then
XCTAssertNotNil(clickStream?.dataSource)
}
}

extension ClickstreamTests: ClickstreamDataSource {
func currentUserLocation() -> CSLocation? {
return CSLocation(longitude: 0.0, latitude: 0.0)
}

func currentNTPTimestamp() -> Date? {
return Date()
}
}
26 changes: 0 additions & 26 deletions ClickstreamTests/Core/Mocks/MockConstants.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EventProcessorDependenciesTests: XCTestCase {

func testMakeEventProcessor() {
// given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let prioritiesMock = [Priority(priority: 0, identifier: "realTime", maxBatchSize: 50000.0, maxTimeBetweenTwoBatches: 1)]

let networkService = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: mockQueue)
Expand Down
4 changes: 2 additions & 2 deletions ClickstreamTests/EventProcessorTests/EventProcessorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SwiftProtobuf
class EventProcessorTest: XCTestCase {

private let processorQueueMock = SerialQueue(label: "com.mock.gojek.clickstream.processor", qos: .utility)
private var config: NetworkConfigurations!
private var config: DefaultNetworkConfiguration!
private var networkService: DefaultNetworkService<SocketHandlerMockSuccess>!
private var retryMech: DefaultRetryMechanism!
private var networkBuilder: DefaultNetworkBuilder!
Expand All @@ -33,7 +33,7 @@ class EventProcessorTest: XCTestCase {
override func setUp() {
//given
/// Network builder
config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
networkService = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: .main)
persistence = DefaultDatabaseDAO<EventRequest>(database: database, performOnQueue: dbQueueMock)
eventPersistence = DefaultDatabaseDAO<Event>(database: database, performOnQueue: dbQueueMock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class EventBatchProcessorTests: XCTestCase {
realTimeEvent = Event(guid: "realTime", timestamp: Date(), type: "realTime", eventProtoData: Data())
standardEvent = Event(guid: "standard", timestamp: Date(), type: "standard", eventProtoData: Data())

Clickstream.constraints = MockConstants.constraints
Clickstream.constraints = ClickstreamConstraints()
Tracker.debugMode = true
}

func test_whenBatchSizeIsGiven_shouldForwardABatch() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should respond on the given queue")

let prioritiesMock = [Priority(priority: 0, identifier: "realTime", maxBatchSize: 50000.0, maxTimeBetweenTwoBatches: 1)]
Expand Down Expand Up @@ -69,7 +70,7 @@ class EventBatchProcessorTests: XCTestCase {

func test_whenAppStateIsEnterBackground_thenAllEventsMustBeFlushed() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "All events must get flushed")

let prioritiesMock = [Priority(priority: 0, identifier: "realTime", maxBatchSize: 5000.0, maxTimeBetweenTwoBatches: 10),
Expand Down
8 changes: 4 additions & 4 deletions ClickstreamTests/EventSchedulerTests/EventCreatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EventCreatorTests: XCTestCase {

func test_whenReachableMockService_shouldReturnCanForwardAsTrue() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))

let networkService = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: networkQueue)
let deviceStatus = DefaultDeviceStatus(performOnQueue: networkQueue)
Expand All @@ -38,7 +38,7 @@ class EventCreatorTests: XCTestCase {

func test_whenNotReachableMockService_shouldReturnCanForwardAsFalse() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))

let deviceStatus = DefaultDeviceStatus(performOnQueue: networkQueue)
let networkService = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: networkQueue)
Expand All @@ -55,7 +55,7 @@ class EventCreatorTests: XCTestCase {

func test_whenReachableMockService_shouldReturnTrue() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))

let deviceStatus = DefaultDeviceStatus(performOnQueue: networkQueue)
let event = Event(guid: "", timestamp: Date(), type: "realTime", eventProtoData: Data())
Expand All @@ -76,7 +76,7 @@ class EventCreatorTests: XCTestCase {

func test_whenNotReachableMockService_shouldReturnFalse() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))

let event = Event(guid: "", timestamp: Date(), type: "realTime", eventProtoData: Data())
let deviceStatus = DefaultDeviceStatus(performOnQueue: networkQueue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EventSchedulerDependenciesTests: XCTestCase {

func testInit() {
// given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))

let networkService = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: mockQueue)
let deviceStatus = DefaultDeviceStatus(performOnQueue: mockQueue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class EventWarehouserTests: XCTestCase {

override func setUp() {

Clickstream.constraints = MockConstants.constraints
Clickstream.constraints = ClickstreamConstraints()
Tracker.debugMode = true
}

func test_whenAnEventIsGiven_thenTheWarehouserMustStoreIt() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should respond on the given queue")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ class NetworkManagerDependenciesTests: XCTestCase {

func testMakeNetworkBuilder() throws {
// given
let accessToken = "dummy_token"
let headers = ["Authorization": "Bearer \(accessToken)"]
let url = URL(string: "ws://mock.clickstream.com/events")!
Clickstream.constraints = MockConstants.constraints
Clickstream.eventClassifier = MockConstants.eventClassification
let networkConfigurations = NetworkConfigurations(baseURL: url, headers: headers)
let dummyRequest = URLRequest(url: URL(string: "dummy_url")!)
Clickstream.constraints = ClickstreamConstraints()
Clickstream.eventClassifier = ClickstreamEventClassification()
// when
let networkManagerDependencies = NetworkManagerDependencies(with: networkConfigurations, db: database)
let networkManagerDependencies = NetworkManagerDependencies(with: dummyRequest, db: database)

let networkBuilder: NetworkBuildable = networkManagerDependencies.makeNetworkBuilder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NetworkBuilderTests: XCTestCase {

func test_whenSerialisableMockDataIsPassed_shouldNotThrowException() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))

let expectation = self.expectation(description: "Should not throw exception")

Expand All @@ -47,7 +47,7 @@ class NetworkBuilderTests: XCTestCase {

func test_whenNetworkIsConnected_thenIsConnectedFlagMustBeSet() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should return isAvailable flag as true")

let mockQueue = SerialQueue(label: "com.mock.gojek.clickstream.network", qos: .utility)
Expand All @@ -74,7 +74,7 @@ class NetworkBuilderTests: XCTestCase {
func test_whenNetworkIsConnectedAndAppMovesToBackground_thenIsConnectedFlagMustNotBeSet() {

//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should return isAvailable flag as false")

let mockQueue = SerialQueue(label: "com.mock.gojek.clickstream.network", qos: .utility)
Expand All @@ -89,13 +89,13 @@ class NetworkBuilderTests: XCTestCase {

//when
let sut = DefaultNetworkBuilder(networkConfigs: config, retryMech: retryMech, performOnQueue: mockQueue)
SerialQueue.main.asyncAfter(deadline: .now() + 3.0) {
SerialQueue.main.asyncAfter(deadline: .now() + 10) {
XCTAssertEqual(sut.isAvailable, false)
expectation.fulfill()
}

//then
wait(for: [expectation], timeout: 5.0)
wait(for: [expectation], timeout: 10.0)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NetworkServiceTests: XCTestCase {

func test_whenMockDataIsPassed_shouldReturnConnectedResponse() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/mock/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should return correct data")
let sut = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: .main)

Expand All @@ -33,7 +33,7 @@ class NetworkServiceTests: XCTestCase {

func test_whenMockDataIsPassed_shouldWriteSuccessfully() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/mock/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should return correct data")
let sut = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: .main)

Expand All @@ -56,7 +56,7 @@ class NetworkServiceTests: XCTestCase {

func test_whenMockDataIsPassed_shouldDisconnectSuccessfully() {
//given
let config = NetworkConfigurations(baseURL: URL(string: "ws://mock.clickstream.com/mock/events")!)
let config = DefaultNetworkConfiguration(request: URLRequest(url: URL(string: "ws://mock.clickstream.com")!))
let expectation = self.expectation(description: "Should return malformed url error")

let sut = DefaultNetworkService<SocketHandlerMockSuccess>(with: config, performOnQueue: .main)
Expand Down
Loading