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

fix(analytics): AWSPinpointUserProfile Added null check for user attributes #3598

Merged
merged 5 commits into from
Aug 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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