Skip to content

Commit da4a4f9

Browse files
Salakarexaby73
authored andcommitted
fix: android tests for getSessionId
1 parent 2f1c8d9 commit da4a4f9

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

packages/firebase_analytics/firebase_analytics/android/src/main/java/io/flutter/plugins/firebase/analytics/FlutterFirebaseAnalyticsPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ private Task<Long> handleGetSessionId() {
165165
cachedThreadPool.execute(
166166
() -> {
167167
try {
168-
Log.d("ANALYTICS: ", analytics.getSessionId().toString());
169168
taskCompletionSource.setResult(Tasks.await(analytics.getSessionId()));
170169
} catch (Exception e) {
171170
taskCompletionSource.setException(e);

tests/integration_test/firebase_analytics/firebase_analytics_e2e_test.dart

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,29 @@ void main() {
1919
);
2020
});
2121

22+
// getSessionId has to be first, else Android returns null
23+
test(
24+
'getSessionId',
25+
() async {
26+
if (kIsWeb) {
27+
await expectLater(
28+
FirebaseAnalytics.instance.getSessionId(),
29+
throwsA(isA<UnimplementedError>()),
30+
);
31+
} else {
32+
await expectLater(
33+
FirebaseAnalytics.instance.setConsent(
34+
analyticsStorageConsentGranted: true,
35+
),
36+
completes,
37+
);
38+
39+
final result = await FirebaseAnalytics.instance.getSessionId();
40+
expect(result, isA<int>());
41+
}
42+
},
43+
);
44+
2245
test('isSupported', () async {
2346
final result = await FirebaseAnalytics.instance.isSupported();
2447
expect(result, isA<bool>());
@@ -272,31 +295,5 @@ void main() {
272295
expect(result2, isA<String>());
273296
}
274297
});
275-
276-
test(
277-
'getSessionId',
278-
() async {
279-
// FIXME: Android returns null for getSessionId in tests,
280-
// but works when running in the context of an app.
281-
// Need to investigate why this is the case.
282-
if (kIsWeb) {
283-
await expectLater(
284-
FirebaseAnalytics.instance.getSessionId(),
285-
throwsA(isA<UnimplementedError>()),
286-
);
287-
} else {
288-
await expectLater(
289-
FirebaseAnalytics.instance.setConsent(
290-
analyticsStorageConsentGranted: true,
291-
adStorageConsentGranted: true,
292-
),
293-
completes,
294-
);
295-
296-
final result = await FirebaseAnalytics.instance.getSessionId();
297-
expect(result, isA<int>());
298-
}
299-
},
300-
);
301298
});
302299
}

0 commit comments

Comments
 (0)