diff --git a/packages/core/lib/event.dart b/packages/core/lib/event.dart index 50f7ba3..a94cf47 100644 --- a/packages/core/lib/event.dart +++ b/packages/core/lib/event.dart @@ -349,7 +349,7 @@ class Context extends JSONExtendableImpl { nativeContext.library as NativeContextLibrary), locale = nativeContext.locale ?? "", network = nativeContext.network == null - ? ContextNetwork(false, false) + ? ContextNetwork(false, false, false) : ContextNetwork.fromNative( nativeContext.network as NativeContextNetwork), os = nativeContext.os == null @@ -370,7 +370,7 @@ class Context extends JSONExtendableImpl { "device", "library", "locale", - "networm", + "network", "os", "screen", "timezone", @@ -495,18 +495,20 @@ class ContextOS extends JSONExtendableImpl { class ContextNetwork extends JSONExtendableImpl { bool cellular; bool wifi; + bool bluetooth; - ContextNetwork(this.cellular, this.wifi, {super.custom}); + ContextNetwork(this.cellular, this.wifi, this.bluetooth, {super.custom}); ContextNetwork.fromNative(NativeContextNetwork nativeContextNetwork) : cellular = nativeContextNetwork.cellular ?? false, - wifi = nativeContextNetwork.wifi ?? false; + wifi = nativeContextNetwork.wifi ?? false, + bluetooth = nativeContextNetwork.bluetooth ?? false; factory ContextNetwork.fromJson(Map json) => JSONExtendable.fromJson( json, _$ContextNetworkFromJson, ContextNetwork._builtInKeys); Map toJson() => _toJson(_$ContextNetworkToJson(this)); - static final Set _builtInKeys = {"cellular", "wifi"}; + static final Set _builtInKeys = {"cellular", "wifi", "bluetooth"}; } @JsonSerializable(explicitToJson: true, includeIfNull: false) @@ -515,8 +517,7 @@ class ContextScreen extends JSONExtendableImpl { int width; double? density; // android only - ContextScreen(this.height, this.width, - {this.density, super.custom}); + ContextScreen(this.height, this.width, {this.density, super.custom}); ContextScreen.fromNative(NativeContextScreen nativeContextScreen) : height = nativeContextScreen.height ?? 0, width = nativeContextScreen.width ?? 0, @@ -667,5 +668,5 @@ ContextDevice mergeContextDevice(ContextDevice a, ContextDevice b) { } ContextScreen mergeContextScreen(ContextScreen a, ContextScreen b) { - return ContextScreen(a.height, b.width, density: a.density ?? b.density); + return ContextScreen(a.height, a.width, density: a.density ?? b.density); } diff --git a/packages/core/lib/event.g.dart b/packages/core/lib/event.g.dart index 2ace323..63c67ad 100644 --- a/packages/core/lib/event.g.dart +++ b/packages/core/lib/event.g.dart @@ -459,6 +459,7 @@ ContextNetwork _$ContextNetworkFromJson(Map json) => ContextNetwork( json['cellular'] as bool, json['wifi'] as bool, + json['bluetooth'] as bool, custom: json['custom'] as Map?, ); @@ -467,6 +468,7 @@ Map _$ContextNetworkToJson(ContextNetwork instance) => 'custom': instance.custom, 'cellular': instance.cellular, 'wifi': instance.wifi, + 'bluetooth': instance.bluetooth, }; ContextScreen _$ContextScreenFromJson(Map json) => diff --git a/packages/core/lib/state.g.dart b/packages/core/lib/state.g.dart index 0eb2f14..bb848e3 100644 --- a/packages/core/lib/state.g.dart +++ b/packages/core/lib/state.g.dart @@ -35,7 +35,7 @@ Map _$UserInfoToJson(UserInfo instance) { } DeepLinkData _$DeepLinkDataFromJson(Map json) => DeepLinkData( - json['referring_application'] as String?, + json['referringApplication'] as String?, json['url'] as String, ); @@ -48,7 +48,7 @@ Map _$DeepLinkDataToJson(DeepLinkData instance) { } } - writeNotNull('referring_application', instance.referringApplication); + writeNotNull('referringApplication', instance.referringApplication); val['url'] = instance.url; return val; } diff --git a/packages/core/test/events_test.dart b/packages/core/test/events_test.dart index 0453566..f0a9e43 100644 --- a/packages/core/test/events_test.dart +++ b/packages/core/test/events_test.dart @@ -25,12 +25,7 @@ class MockPlatform extends AnalyticsPlatform { return Future.value(mockNativeContext); } - final List contextObj = [ - "build", - "name", - "namespace", - "version" - ]; + final List contextObj = ["build", "name", "namespace", "version"]; final List deviceObj = [ "id", @@ -44,27 +39,13 @@ class MockPlatform extends AnalyticsPlatform { "token" ]; - final List libraryObj = [ - "name", - "version" - ]; + final List libraryObj = ["name", "version"]; - final List networkObj = [ - true, - false, - false - ]; + final List networkObj = [true, false, false]; - final List osObj = [ - "name", - "version" - ]; + final List osObj = ["name", "version"]; - final List screenObj = [ - 100, - 100, - 5.5 - ]; + final List screenObj = [100, 100, 5.5]; Object buildObject() { final List encondeObj = [ @@ -146,6 +127,18 @@ void main() { reverseContext.traits.custom["custom"]); }); + test("NativeContext to/from json doesn't change values", () async { + var context = Context.fromNative(NativeContext(), UserTraits()); + var tempJson = context.toJson(); + for (var i = 0; i < 5; i++) { + final contextStr = jsonEncode(tempJson); + final reverseContextJson = jsonDecode(contextStr); + final reverseContext = Context.fromJson(reverseContextJson); + tempJson = reverseContext.toJson(); + } + expect(context.toJson(), tempJson); + }); + test("Test encode method on NativeContext", () async { final context = await AnalyticsPlatform.instance.getContext(); final contextEncode = context.encode(); @@ -186,6 +179,5 @@ void main() { final nativeContextApi = NativeContextApi(); nativeContextApi.getContext(true); }); - }); }