-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[NT-685] Abstract TrackingClient to be configurable #983
Conversation
Library/TestHelpers/TestCase.swift
Outdated
internal let dateType = MockDate.self | ||
internal let mainBundle = MockBundle() | ||
internal let reachability = MutableProperty(Reachability.wifi) | ||
internal let scheduler = TestScheduler(startDate: MockDate().date) | ||
internal let trackingClient = MockTrackingClient() | ||
internal let trackingClient = MockTrackingClient() // TODO: Rename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming this resulted in ~700 changes so I will do that separately.
@@ -54,7 +55,11 @@ internal class TestCase: FBSnapshotTestCase { | |||
debounceInterval: .seconds(0), | |||
device: MockDevice(), | |||
isVoiceOverRunning: { false }, | |||
koala: Koala(client: self.trackingClient, loggedInUser: nil), | |||
koala: Koala( | |||
dataLakeClient: self.dataLakeTrackingClient, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a mock client set for this by default in TestCase
but I think we can add tests once we whitelist events.
Library/Tracking/Koala.swift
Outdated
@@ -355,15 +356,17 @@ public final class Koala { | |||
|
|||
public init( | |||
bundle: NSBundleType = Bundle.main, | |||
client: TrackingClientType, | |||
dataLakeClient: TrackingClientType = TrackingClient(.dataLake), // TODO: Remove default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to reduce the amount of line changes in this PR I'm passing in a default value here. We can tackle this separately.
@@ -2028,7 +2031,12 @@ public final class Koala { | |||
|
|||
self.logEventCallback?(event, props) | |||
|
|||
self.client.track( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we just send all events to both clients. We will whitelist before this point.
|
||
if dataString.count >= 10_000 { | ||
// swiftlint:disable:next line_length | ||
print("\(config.identifier.emoji) [\(config.identifier) Error]: Base64 payload is longer than 10,000 characters.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just something we printed at this point previously, not sure how important it is to keep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start! Really easy to follow and keeps things pretty DRY. Nice work! 👏
Generated by 🚫 Danger |
6148b32
to
8d87cd1
Compare
📲 What
Renames our existing
KoalaTrackingClient
toTrackingClient
and addsTrackingClientConfiguration
which is a struct with which we can initializeTrackingClient
so that we can use it for more than one tracking endpoint.Note: We could even create a
TrackingClient
to forward our events to something likeCrashlytics
for our breadcrumbs. Currently we do this with a callback at the time of tracking, but I think we should move that to be its ownTrackingClient
.Also note:
Koala
itself will be renamed separately too. Currently it really just behaves as an interface for sending the events to the clients.🤔 Why
We're going to be sending tracking events to two endpoints until we're able to fully deprecate
Koala
, this allows us to do so in a somewhat controlled manner and still keeps things testable.🛠 How
TrackingClient
toTrackingClientConfiguration
either via simple properties or closures.Koala
's initializer so that it can be initialized with two tracking clients.Koala
will send all tracking events to both clients, we will be doing some filtering of whitelisted events one we know what they are. I would suggest that we do this filtering inKoala
so that we can test it through mocked clients.TrackingClientConfiguration
, this actually gives us a bit more test coverage than before because these parts ofKoalaTrackingClient
weren't tested.✅ Acceptance criteria
With the simulator set to staging, return
true
forisKoalaTrackingEnabled
(to be renamed) inEnvironmentVariables.swift
. Use Charles Proxy to inspect traffic.DataLake
andKoala
endpoint.200
and are in the correct structure for each endpoint (e.g.POST
forKoala
,PUT
forDataLake
, etc.).⏰ TODO