Skip to content

Commit

Permalink
fix: track events type in HTTP requests (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
levibostian committed Jan 14, 2022
1 parent ac66abd commit 745d4ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/Tracking/CustomerIOImplementation+ScreenViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public extension CustomerIOImplementation {
method_exchangeImplementations(originalMethod, swizzleMethod)
}
}

internal extension UIViewController {
var defaultScreenViewBody: ScreenViewData {
ScreenViewData()
Expand Down Expand Up @@ -43,6 +44,7 @@ internal extension UIViewController {
}
CustomerIO.shared.screen(name: name, data: data)
}

/**
Finds the top most view controller in the navigation controller/ tab bar controller stack or if it is presented
*/
Expand All @@ -60,9 +62,10 @@ internal extension UIViewController {
}
return controller
}

/**
Finds out the active root view controller by checking whether the app uses window via AppDelegate or SceneDelegate
- returns: If window is not found then this function returns nil else returns the root view controller
*/
private func activeRootViewController() -> UIViewController? {
Expand Down
1 change: 1 addition & 0 deletions Sources/Tracking/Service/Request/TrackRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal struct TrackRequestBody<T: Encodable>: Encodable {
/// provide keys because we allow customer to set custom JSONEncoder and we want to enforce that the keys
/// are what the Customer.io API expects. the custom JSONEncoder will be used for `data` encoding.
private enum CodingKeys: String, CodingKey {
case type
case name
case data
case timestamp
Expand Down
23 changes: 23 additions & 0 deletions Tests/Tracking/Service/Request/TrackRequestBody.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@testable import CioTracking
import Foundation
import SharedTests
import XCTest

class TrackRequestBodyTest: UnitTest {
func test_screenview_expectJsonStringApiRequires() {
let attributes = ["logged_in": false]
let given = TrackRequestBody(type: .screen, name: "Dashboard", data: attributes,
timestamp: Date(timeIntervalSince1970: 1642018466))
let expectedJson = """
{"data":{"logged_in":false},"name":"Dashboard","timestamp":1642018466,"type":"screen"}
"""

guard let jsonData = jsonAdapter.toJson(given, encoder: nil), let actualJson = jsonData.string else {
return XCTFail()
}

print(actualJson)

XCTAssertEqual(expectedJson, actualJson)
}
}

0 comments on commit 745d4ad

Please sign in to comment.