@@ -6,6 +6,7 @@ import 'dart:mirrors';
6
6
7
7
import 'package:test/test.dart' ;
8
8
import 'package:unified_analytics/src/enums.dart' ;
9
+ import 'package:unified_analytics/src/event.dart' ;
9
10
import 'package:unified_analytics/unified_analytics.dart' ;
10
11
11
12
void main () {
@@ -576,11 +577,14 @@ void main() {
576
577
isEmbedded: 'isEmbedded' ,
577
578
ideLaunchedFeature: 'ideLaunchedFeature' ,
578
579
isWasm: 'true' ,
579
- additionalMetrics: {
580
- 'someMetric' : 100 ,
581
- 'otherMetric' : false ,
582
- 'shouldBeRemoved' : null ,
583
- },
580
+ additionalMetrics: _TestMetrics (
581
+ stringField: 'test' ,
582
+ // Since this value is null, it should not be included in the event
583
+ // JSON below.
584
+ nullableField: null ,
585
+ intField: 100 ,
586
+ boolField: false ,
587
+ ),
584
588
);
585
589
586
590
final constructedEvent = generateEvent ();
@@ -606,9 +610,11 @@ void main() {
606
610
'ideLaunchedFeature' ,
607
611
);
608
612
expect (constructedEvent.eventData['isWasm' ], 'true' );
609
- expect (constructedEvent.eventData['someMetric' ], 100 );
610
- expect (constructedEvent.eventData['otherMetric' ], false );
611
- expect (constructedEvent.eventData.length, 19 );
613
+ expect (constructedEvent.eventData['stringField' ], 'test' );
614
+ expect (constructedEvent.eventData['intField' ], 100 );
615
+ expect (constructedEvent.eventData['boolField' ], false );
616
+ expect (constructedEvent.eventData.containsKey ('nullableField' ), false );
617
+ expect (constructedEvent.eventData.length, 20 );
612
618
});
613
619
614
620
test ('Confirm all constructors were checked' , () {
@@ -682,3 +688,25 @@ void main() {
682
688
expect (eventConstructed, isNull);
683
689
});
684
690
}
691
+
692
+ class _TestMetrics extends CustomMetrics {
693
+ _TestMetrics ({
694
+ required this .stringField,
695
+ required this .nullableField,
696
+ required this .intField,
697
+ required this .boolField,
698
+ });
699
+
700
+ final String stringField;
701
+ final String ? nullableField;
702
+ final int intField;
703
+ final bool boolField;
704
+
705
+ @override
706
+ Map <String , Object ?> toMap () => {
707
+ 'stringField' : stringField,
708
+ 'nullableField' : nullableField,
709
+ 'intField' : intField,
710
+ 'boolField' : boolField,
711
+ };
712
+ }
0 commit comments