Skip to content

Commit ffc624c

Browse files
EquarteyDillon Nys
authored andcommitted
fix(analytics): AWSPinpointUserProfile Added null check for user attributes (#3598)
1 parent cbac941 commit ffc624c

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

packages/analytics/amplify_analytics_pinpoint_dart/lib/src/impl/analytics_client/endpoint_client/endpoint_client.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ class EndpointClient {
133133
.addMetrics(userProfile.customProperties!.metrics);
134134
}
135135

136-
if (userProfile is AWSPinpointUserProfile) {
136+
if (userProfile is AWSPinpointUserProfile &&
137+
userProfile.userAttributes != null) {
137138
newUserBuilder.userAttributes =
138139
ListMultimapBuilder(userProfile.userAttributes);
139140
}

packages/analytics/amplify_analytics_pinpoint_dart/test/common/mock_endpoint_values.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import 'package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/endpoint_client/aws_pinpoint_user_profile.dart';
45
import 'package:amplify_analytics_pinpoint_dart/src/sdk/src/pinpoint/model/channel_type.dart';
56
import 'package:amplify_core/amplify_core.dart';
67

@@ -25,6 +26,13 @@ final userProfile = UserProfile(
2526
customProperties: analyticsProperties,
2627
);
2728

29+
final pinpointUserProfileNullUserAttribute = AWSPinpointUserProfile(
30+
name: 'name',
31+
email: 'email',
32+
plan: 'plan',
33+
location: userLocation,
34+
);
35+
2836
const channelType = ChannelType.apns;
2937
const address = 'address';
3038
const optOut = 'OPT-OUT';

packages/analytics/amplify_analytics_pinpoint_dart/test/endpoint_client_test.dart

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:amplify_analytics_pinpoint_dart/src/impl/analytics_client/endpoi
77
import 'package:amplify_analytics_pinpoint_dart/src/sdk/pinpoint.dart';
88
import 'package:amplify_core/amplify_core.dart';
99
import 'package:mocktail/mocktail.dart';
10-
1110
import 'package:test/test.dart';
1211

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

264+
test(
265+
'setUser handles null user attributes when provided a AWSPinpointUserProfile',
266+
() async {
267+
endpointClient
268+
..channelType = channelType
269+
..address = address
270+
..optOut = optOut;
271+
272+
await endpointClient.setUser(
273+
userId,
274+
pinpointUserProfileNullUserAttribute,
275+
);
276+
277+
final endpoint = endpointClient.getPublicEndpoint();
278+
279+
expect(endpoint.address, address);
280+
expect(endpoint.channelType, channelType);
281+
expect(endpoint.optOut, optOut);
282+
283+
// Attributes
284+
expect(endpoint.attributes, isNotNull);
285+
final attributes = endpoint.attributes!;
286+
287+
expect(attributes['name'], [userProfile.name]);
288+
expect(attributes['email'], [userProfile.email]);
289+
expect(attributes['plan'], [userProfile.plan]);
290+
291+
// Demographic
292+
expect(endpoint.demographic, isNotNull);
293+
final demographic = endpoint.demographic!;
294+
295+
expect(demographic.appVersion, mockDeviceContextInfo.appVersion);
296+
expect(demographic.locale, mockDeviceContextInfo.locale);
297+
expect(demographic.make, mockDeviceContextInfo.make);
298+
expect(demographic.model, mockDeviceContextInfo.model);
299+
expect(demographic.modelVersion, mockDeviceContextInfo.modelVersion);
300+
expect(demographic.platform, mockDeviceContextInfo.platform!.name);
301+
expect(
302+
demographic.platformVersion,
303+
mockDeviceContextInfo.platformVersion,
304+
);
305+
306+
// Location
307+
expect(endpoint.location, isNotNull);
308+
final location = endpoint.location!;
309+
310+
expect(location.city, userLocation.city);
311+
expect(location.country, userLocation.country);
312+
expect(location.latitude, userLocation.latitude);
313+
expect(location.longitude, userLocation.longitude);
314+
expect(location.postalCode, userLocation.postalCode);
315+
expect(location.region, userLocation.region);
316+
317+
// User
318+
expect(endpoint.user, isNotNull);
319+
expect(endpoint.user!.userId, userId);
320+
321+
expect(endpoint.user!.userAttributes, isNull);
322+
});
323+
265324
test(
266325
'updateEndpoint throws AnalyticsException from unrecognized exceptions',
267326
() async {

0 commit comments

Comments
 (0)