Skip to content

Commit

Permalink
fix(analytics): AWSPinpointUserProfile Added null check for user attr…
Browse files Browse the repository at this point in the history
…ibutes (#3598)
  • Loading branch information
Equartey authored and Dillon Nys committed Aug 28, 2023
1 parent cbac941 commit ffc624c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class EndpointClient {
.addMetrics(userProfile.customProperties!.metrics);
}

if (userProfile is AWSPinpointUserProfile) {
if (userProfile is AWSPinpointUserProfile &&
userProfile.userAttributes != null) {
newUserBuilder.userAttributes =
ListMultimapBuilder(userProfile.userAttributes);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/endpoint_client/aws_pinpoint_user_profile.dart';
import 'package:amplify_analytics_pinpoint_dart/src/sdk/src/pinpoint/model/channel_type.dart';
import 'package:amplify_core/amplify_core.dart';

Expand All @@ -25,6 +26,13 @@ final userProfile = UserProfile(
customProperties: analyticsProperties,
);

final pinpointUserProfileNullUserAttribute = AWSPinpointUserProfile(
name: 'name',
email: 'email',
plan: 'plan',
location: userLocation,
);

const channelType = ChannelType.apns;
const address = 'address';
const optOut = 'OPT-OUT';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/endpoi
import 'package:amplify_analytics_pinpoint_dart/src/sdk/pinpoint.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:mocktail/mocktail.dart';

import 'package:test/test.dart';

import 'common/mock_device_context_info.dart';
Expand Down Expand Up @@ -262,6 +261,66 @@ void main() {
expect(endpoint.user!.userAttributes, isNull);
});

test(
'setUser handles null user attributes when provided a AWSPinpointUserProfile',
() async {
endpointClient
..channelType = channelType
..address = address
..optOut = optOut;

await endpointClient.setUser(
userId,
pinpointUserProfileNullUserAttribute,
);

final endpoint = endpointClient.getPublicEndpoint();

expect(endpoint.address, address);
expect(endpoint.channelType, channelType);
expect(endpoint.optOut, optOut);

// Attributes
expect(endpoint.attributes, isNotNull);
final attributes = endpoint.attributes!;

expect(attributes['name'], [userProfile.name]);
expect(attributes['email'], [userProfile.email]);
expect(attributes['plan'], [userProfile.plan]);

// Demographic
expect(endpoint.demographic, isNotNull);
final demographic = endpoint.demographic!;

expect(demographic.appVersion, mockDeviceContextInfo.appVersion);
expect(demographic.locale, mockDeviceContextInfo.locale);
expect(demographic.make, mockDeviceContextInfo.make);
expect(demographic.model, mockDeviceContextInfo.model);
expect(demographic.modelVersion, mockDeviceContextInfo.modelVersion);
expect(demographic.platform, mockDeviceContextInfo.platform!.name);
expect(
demographic.platformVersion,
mockDeviceContextInfo.platformVersion,
);

// Location
expect(endpoint.location, isNotNull);
final location = endpoint.location!;

expect(location.city, userLocation.city);
expect(location.country, userLocation.country);
expect(location.latitude, userLocation.latitude);
expect(location.longitude, userLocation.longitude);
expect(location.postalCode, userLocation.postalCode);
expect(location.region, userLocation.region);

// User
expect(endpoint.user, isNotNull);
expect(endpoint.user!.userId, userId);

expect(endpoint.user!.userAttributes, isNull);
});

test(
'updateEndpoint throws AnalyticsException from unrecognized exceptions',
() async {
Expand Down

0 comments on commit ffc624c

Please sign in to comment.