|
| 1 | +import 'dart:convert'; |
| 2 | +import 'dart:io'; |
| 3 | + |
| 4 | +import 'package:countly_flutter/countly_flutter.dart'; |
| 5 | +import 'package:flutter_foreground_task/flutter_foreground_task.dart'; |
| 6 | +import 'package:flutter_test/flutter_test.dart'; |
| 7 | +import 'package:integration_test/integration_test.dart'; |
| 8 | +import '../utils.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 12 | + testWidgets('test_eventSaveScenario_sessionCallsTriggersSave_M', (WidgetTester tester) async { |
| 13 | + // Initialize the SDK |
| 14 | + CountlyConfig config = CountlyConfig(SERVER_URL, APP_KEY).enableManualSessionHandling().setLoggingEnabled(true); |
| 15 | + await Countly.initWithConfig(config); // generates 0.begin_session |
| 16 | + await Future.delayed(Duration(seconds: 1)); |
| 17 | + |
| 18 | + await Countly.instance.userProfile.setProperty('beforeBeginSession', true); |
| 19 | + await Countly.instance.sessions.beginSession(); |
| 20 | + |
| 21 | + await Countly.instance.userProfile.setProperty('beforeUpdateSession', true); |
| 22 | + await Future.delayed(Duration(seconds: 2)); |
| 23 | + await Countly.instance.sessions.updateSession(); |
| 24 | + |
| 25 | + await Countly.instance.userProfile.setProperty('beforeEndSession', true); |
| 26 | + await Future.delayed(Duration(seconds: 2)); // wait for session to end |
| 27 | + await Countly.instance.sessions.endSession(); |
| 28 | + |
| 29 | + // Get request queue from native side |
| 30 | + List<Map<String, List<String>>> requestList = (await getRequestQueue()).map((e) => Uri.parse("?" + e).queryParametersAll).toList(); |
| 31 | + |
| 32 | + // Currently |
| 33 | + // 0- user properties: beforeBeginSession |
| 34 | + // 1- begin_session |
| 35 | + // 2- orientation |
| 36 | + // 3- user properties: beforeUpdateSession |
| 37 | + // 4- session_duration |
| 38 | + // 5- user properties: beforeEndSession |
| 39 | + // 6- end_session |
| 40 | + expect(requestList.length, 7); |
| 41 | + |
| 42 | + testCommonRequestParams(requestList[0]); |
| 43 | + expect(requestList[0]['user_details']?[0], '{"custom":{"beforeBeginSession":${Platform.isAndroid ? '"true"' : 'true'}}}'); |
| 44 | + |
| 45 | + testCommonRequestParams(requestList[1]); // tests |
| 46 | + checkBeginSession(requestList[1]); |
| 47 | + |
| 48 | + expect(requestList[2]['events']?[0].contains('[CLY]_orientation'), true); |
| 49 | + |
| 50 | + testCommonRequestParams(requestList[3]); |
| 51 | + expect(requestList[3]['user_details']?[0], '{"custom":{"beforeUpdateSession":${Platform.isAndroid ? '"true"' : 'true'}}}'); |
| 52 | + |
| 53 | + testCommonRequestParams(requestList[4]); |
| 54 | + expect(requestList[4]['session_duration']?[0], '2'); |
| 55 | + |
| 56 | + testCommonRequestParams(requestList[5]); |
| 57 | + expect(requestList[5]['user_details']?[0], '{"custom":{"beforeEndSession":${Platform.isAndroid ? '"true"' : 'true'}}}'); |
| 58 | + |
| 59 | + testCommonRequestParams(requestList[6]); |
| 60 | + checkEndSession(requestList[6]); |
| 61 | + }); |
| 62 | +} |
0 commit comments