|
| 1 | +import 'dart:convert'; |
| 2 | +import 'dart:io'; |
| 3 | + |
| 4 | +import 'package:countly_flutter/countly_flutter.dart'; |
| 5 | +import 'package:flutter_test/flutter_test.dart'; |
| 6 | +import 'package:integration_test/integration_test.dart'; |
| 7 | +import '../utils.dart'; |
| 8 | + |
| 9 | +/// Check if setting setMaxValueSize to 1 truncates the values |
| 10 | +/// Tested values are: |
| 11 | +/// - Event and View segmentation values |
| 12 | +/// - Custom Crash segmentation values |
| 13 | +/// - Global View and Crash segmentation values |
| 14 | +/// - Custom User Property values and their modifications (with mul, push, pull, set, increment, etc) |
| 15 | +/// - User Profile named key (username, email, etc) values (except the "picture" field, which has a limit of 4096 chars) |
| 16 | +/// - Breadcrumb value (text) |
| 17 | +/// - TODO: Manual Feedback and Rating Widgets reporting fields |
| 18 | +
|
| 19 | +const int MAX_VALUE_SIZE = 1; |
| 20 | +void main() { |
| 21 | + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); |
| 22 | + testWidgets('Init SDK with setMaxValueSize', (WidgetTester tester) async { |
| 23 | + // Initialize the SDK |
| 24 | + CountlyConfig config = CountlyConfig(SERVER_URL, APP_KEY).setLoggingEnabled(true); |
| 25 | + config.sdkInternalLimits.setMaxValueSize(MAX_VALUE_SIZE); |
| 26 | + await Countly.initWithConfig(config); |
| 27 | + |
| 28 | + // Create truncable events |
| 29 | + await createTruncableEvents(); |
| 30 | + |
| 31 | + // Get request and event queues from native side |
| 32 | + List<String> requestList = await getRequestQueue(); |
| 33 | + List<String> eventList = await getEventQueue(); |
| 34 | + |
| 35 | + // Some logs for debugging |
| 36 | + print('RQ: $requestList'); |
| 37 | + print('EQ: $eventList'); |
| 38 | + print('RQ length: ${requestList.length}'); |
| 39 | + print('EQ length: ${eventList.length}'); |
| 40 | + |
| 41 | + expect(requestList.length, Platform.isIOS ? 8 : 7); // user properties and custom user properties are separately sent in iOS |
| 42 | + expect(eventList.length, 0); |
| 43 | + |
| 44 | + // TODO: refactor this part (move to utils and make it more generic) |
| 45 | + // 0: begin session |
| 46 | + // 1: custom APM with segmentation |
| 47 | + // 2: network Trace |
| 48 | + // 3: custom fatality crash with segmentation |
| 49 | + // 4: custom mortal crash with segmentation |
| 50 | + // 5: custom view and events with segmentation |
| 51 | + // 6: custom user properties |
| 52 | + var a = 0; |
| 53 | + for (var element in requestList) { |
| 54 | + Map<String, List<String>> queryParams = Uri.parse('?' + element).queryParametersAll; |
| 55 | + testCommonRequestParams(queryParams); // checks general params |
| 56 | + if (a == 1) { |
| 57 | + Map<String, dynamic> apm = json.decode(queryParams['apm']![0]); |
| 58 | + expect(apm['name'], 'Trace'); |
| 59 | + expect(apm['apm_metrics']['C44CCC'], 1337); |
| 60 | + expect(apm['apm_metrics']['ABCDEF'], 1233); |
| 61 | + } else if (a == 2) { |
| 62 | + Map<String, dynamic> apm = json.decode(queryParams['apm']![0]); |
| 63 | + expect(apm['name'], 'Network Trace'); |
| 64 | + } else if (a == 3 || a == 4) { |
| 65 | + Map<String, dynamic> crash = json.decode(queryParams['crash']![0]); |
| 66 | + expect(crash['_custom']['Cats'], '12345'.substring(0, MAX_VALUE_SIZE)); |
| 67 | + expect(crash['_custom']['Moose'], 'Deer'.substring(0, MAX_VALUE_SIZE)); |
| 68 | + expect(crash['_custom']['Moons'], '9.9866'.substring(0, MAX_VALUE_SIZE)); |
| 69 | + expect(crash['_logs'], 'User Performed Step A'.substring(0, MAX_VALUE_SIZE) + '\n'); |
| 70 | + } else if (a == 5) { |
| 71 | + // 0) Custom Event |
| 72 | + List<dynamic> eventList = json.decode(queryParams['events']![0]); |
| 73 | + var event = eventList[0]; |
| 74 | + expect(event['key'], 'Event With Sum And Segment'); |
| 75 | + expect(event['segmentation']['Country'], 'Turkey'.substring(0, MAX_VALUE_SIZE)); |
| 76 | + expect(event['segmentation']['Age'], '28884'.substring(0, MAX_VALUE_SIZE)); |
| 77 | + // 1) View Start (legacy) |
| 78 | + var view = eventList[1]; |
| 79 | + expect(view['key'], '[CLY]_view'); |
| 80 | + expect(view['segmentation']['Cats'], '12345'.substring(0, MAX_VALUE_SIZE)); |
| 81 | + expect(view['segmentation']['Moons'], '9.9866'.substring(0, MAX_VALUE_SIZE)); |
| 82 | + expect(view['segmentation']['segment'], Platform.isIOS ? 'iOS' : 'Android'); |
| 83 | + expect(view['segmentation']['start'], '1'); |
| 84 | + expect(view['segmentation']['name'], 'HomePage'); |
| 85 | + expect(view['segmentation']['Camel'], 666); |
| 86 | + expect(view['segmentation']['visit'], '1'); |
| 87 | + expect(view['segmentation']['NotCamel'], 'Deerz'.substring(0, MAX_VALUE_SIZE)); |
| 88 | + expect(view['segmentation']['Moose'], 'Deer'.substring(0, MAX_VALUE_SIZE)); |
| 89 | + // 2) View End (legacy) |
| 90 | + view = eventList[2]; |
| 91 | + expect(view['key'], '[CLY]_view'); |
| 92 | + expect(view['segmentation']['segment'], Platform.isIOS ? 'iOS' : 'Android'); |
| 93 | + expect(view['segmentation']['name'], 'HomePage'); |
| 94 | + expect(view['segmentation']['Camel'], 666); |
| 95 | + expect(view['segmentation']['NotCamel'], 'Deerz'.substring(0, MAX_VALUE_SIZE)); |
| 96 | + // 3) View Start (AutoStopped) |
| 97 | + view = eventList[3]; |
| 98 | + expect(view['key'], '[CLY]_view'); |
| 99 | + expect(view['segmentation']['Cats'], 12345); |
| 100 | + expect(view['segmentation']['Moons'], 9.9866); |
| 101 | + expect(view['segmentation']['segment'], Platform.isIOS ? 'iOS' : 'Android'); |
| 102 | + expect(view['segmentation']['name'], 'hawk'); |
| 103 | + expect(view['segmentation']['Camel'], 666); |
| 104 | + expect(view['segmentation']['visit'], '1'); |
| 105 | + expect(view['segmentation']['NotCamel'], 'Deerz'.substring(0, MAX_VALUE_SIZE)); |
| 106 | + expect(view['segmentation']['Moose'], 'Deer'.substring(0, MAX_VALUE_SIZE)); |
| 107 | + // 4) View End (AutoStopped) |
| 108 | + view = eventList[4]; |
| 109 | + expect(view['key'], '[CLY]_view'); |
| 110 | + expect(view['segmentation']['segment'], Platform.isIOS ? 'iOS' : 'Android'); |
| 111 | + expect(view['segmentation']['name'], 'hawk'); |
| 112 | + expect(view['segmentation']['Camel'], 666); |
| 113 | + expect(view['segmentation']['NotCamel'], 'Deerz'.substring(0, MAX_VALUE_SIZE)); |
| 114 | + } else if (a == 6) { |
| 115 | + Map<String, dynamic> userDetails = json.decode(queryParams['user_details']![0]); |
| 116 | + checkUnchangingUserPropeties(userDetails); |
| 117 | + expect(userDetails['custom']['special_value'], 'something special'.substring(0, MAX_VALUE_SIZE)); |
| 118 | + expect(userDetails['custom']['not_special_value'], 'something special cooking'.substring(0, MAX_VALUE_SIZE)); |
| 119 | + |
| 120 | + // TODO: this should be in a==7 for ios |
| 121 | + expect(userDetails['custom']['setProperty'], 'My Property'.substring(0, MAX_VALUE_SIZE)); |
| 122 | + } |
| 123 | + |
| 124 | + // some logs for debugging |
| 125 | + print('RQ.$a: $queryParams'); |
| 126 | + print('========================'); |
| 127 | + a++; |
| 128 | + } |
| 129 | + }); |
| 130 | +} |
0 commit comments