-
Notifications
You must be signed in to change notification settings - Fork 238
/
identify_user_test.dart
125 lines (111 loc) · 3.93 KB
/
identify_user_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import 'dart:async';
import 'package:amplify_analytics_pinpoint_dart/src/sdk/pinpoint.dart'
show EndpointLocation;
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'utils/mock_data.dart';
import 'utils/setup_utils.dart';
import 'utils/test_event.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('identifyUser', () {
late Stream<TestEvent> eventsStream;
setUpAll(() async {
await configureAnalytics();
eventsStream = await subscribeToEvents();
});
testWidgets(
'properties of identityUser() added to all future events',
(_) async {
final userId = DateTime.now().toIso8601String();
const name = 'name';
const email = 'email';
const plan = 'plan';
const latitude = 43.0;
const longitude = 12.0;
const postalCode = '94070';
const city = 'city';
const region = 'region';
const country = 'USA';
final location = AnalyticsUserProfileLocation(
latitude: latitude,
longitude: longitude,
postalCode: postalCode,
city: city,
region: region,
country: country,
);
final properties = AnalyticsProperties()
..addBoolProperty(boolProperty.key, boolProperty.value)
..addDoubleProperty(doubleProperty.key, doubleProperty.value)
..addIntProperty(intProperty.key, intProperty.value)
..addStringProperty(stringProperty.key, stringProperty.value);
await Amplify.Analytics.identifyUser(
userId: userId,
userProfile: AnalyticsUserProfile(
name: name,
email: email,
plan: plan,
location: location,
analyticsProperties: properties,
),
);
const customEventName = 'identify user event name';
final customEvent = AnalyticsEvent(customEventName);
await Amplify.Analytics.recordEvent(event: customEvent);
await Amplify.Analytics.flushEvents();
await expectLater(
eventsStream,
emits(
isA<TestEvent>()
.having((e) => e.eventType, 'eventType', customEventName)
.having(
(e) => e.endpoint.endpointStatus,
'EndpointStatus',
'ACTIVE',
)
.having((e) => e.endpoint.optOut, 'OptOut', 'ALL')
.having(
(e) => e.endpoint.location,
'Location',
EndpointLocation(
latitude: latitude,
longitude: longitude,
postalCode: postalCode,
city: city,
region: region,
country: country,
),
)
.having((e) => e.endpoint.user?.userId, 'UserId', userId)
.having(
(e) => e.endpoint.attributes?.toMap() ?? const {},
'Attributes',
equals({
boolProperty.key: [stringifiedBoolProperty.value],
stringProperty.key: [stringProperty.value],
'name': [name],
'plan': [plan],
'email': [email],
}),
)
.having(
(e) => e.endpoint.metrics?.toMap() ?? const {},
'Metrics',
equals(
Map.fromEntries([
lossyDoubleProperty,
intProperty,
]),
),
),
),
);
},
timeout: const Timeout(Duration(minutes: 3)),
);
});
}