Skip to content

Commit

Permalink
chore: register device token (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Nov 15, 2024
1 parent 8197413 commit 8a06a9b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
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 @@ -135,20 +135,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)")
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

0 comments on commit 8a06a9b

Please sign in to comment.