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

chore: register device token #172

Merged
merged 2 commits into from
Nov 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,10 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}

private fun registerDeviceToken(params: Map<String, Any>) {
// TODO: Fix registerDeviceToken implementation
/*
val token = params.getString(Keys.Tracking.TOKEN)
val token = requireNotNull(params.getAsTypeOrNull<String>(Keys.Tracking.TOKEN)) {
"Device token is missing in params: $params"
}
CustomerIO.instance().registerDeviceToken(token)
*/
}

private fun trackMetric(params: Map<String, Any>) {
Expand Down
22 changes: 12 additions & 10 deletions ios/Classes/SwiftCustomerIoPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,22 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin {

private func setProfileAttributes(params : Dictionary<String, AnyHashable>){
guard let attributes = params[Keys.Tracking.traits] as? Dictionary<String, AnyHashable>
else { return }
else {
logger.error("Missing attributes in: \(params) for key: \(Keys.Tracking.traits)")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logs were missing here

return
}

CustomerIO.shared.profileAttributes = attributes
}

private func registerDeviceToken(params : Dictionary<String, AnyHashable>){
// TODO: Fix registerDeviceToken implementation
/*
guard let token = params[Keys.Tracking.token] as? String
else {
return
}

CustomerIO.shared.registerDeviceToken(token)
*/
guard let token = params[Keys.Tracking.token] as? String
else {
logger.error("Missing token in: \(params) for key: \(Keys.Tracking.token)")
return
}

CustomerIO.shared.registerDeviceToken(token)
}

private func trackMetric(params : Dictionary<String, AnyHashable>){
Expand Down
6 changes: 6 additions & 0 deletions test/customer_io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ void main() {
.called(1);
});

test('registerDeviceToken() calls platform', () {
const token = 'abc';
CustomerIO.instance.registerDeviceToken(deviceToken: token);
verify(mockPlatform.registerDeviceToken(deviceToken: token)).called(1);
});

test('track() correct arguments are passed', () {
const name = 'itemAddedToCart';
final givenAttributes = {'name': 'John Doe'};
Expand Down
Loading