diff --git a/packages/flutter/lib/parse_server_sdk_flutter.dart b/packages/flutter/lib/parse_server_sdk_flutter.dart index 2f1f5a2f..aef9fd53 100644 --- a/packages/flutter/lib/parse_server_sdk_flutter.dart +++ b/packages/flutter/lib/parse_server_sdk_flutter.dart @@ -122,6 +122,8 @@ class Parse extends sdk.Parse if (list.contains(ConnectivityResult.wifi)) { return sdk.ParseConnectivityResult.wifi; + } else if (list.contains(ConnectivityResult.ethernet)) { + return sdk.ParseConnectivityResult.ethernet; } else if (list.contains(ConnectivityResult.mobile)) { return sdk.ParseConnectivityResult.mobile; } else { @@ -136,6 +138,8 @@ class Parse extends sdk.Parse ) { if (event.contains(ConnectivityResult.wifi)) { return sdk.ParseConnectivityResult.wifi; + } else if (event.contains(ConnectivityResult.ethernet)) { + return sdk.ParseConnectivityResult.ethernet; } else if (event.contains(ConnectivityResult.mobile)) { return sdk.ParseConnectivityResult.mobile; } else { diff --git a/packages/flutter/test/parse_connectivity_mapping_test.dart b/packages/flutter/test/parse_connectivity_mapping_test.dart new file mode 100644 index 00000000..a5b38703 --- /dev/null +++ b/packages/flutter/test/parse_connectivity_mapping_test.dart @@ -0,0 +1,64 @@ +import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:parse_server_sdk_flutter/parse_server_sdk_flutter.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('Connectivity mapping logic', () { + test('mapping logic follows priority: wifi > ethernet > mobile > none', + () { + // This documents the if-else chain priority in checkConnectivity() + // and connectivityStream mapping logic + + // Simulating the actual mapping logic from parse_server_sdk_flutter.dart + ParseConnectivityResult mapResult(List list) { + if (list.contains(ConnectivityResult.wifi)) { + return ParseConnectivityResult.wifi; + } else if (list.contains(ConnectivityResult.ethernet)) { + return ParseConnectivityResult.ethernet; + } else if (list.contains(ConnectivityResult.mobile)) { + return ParseConnectivityResult.mobile; + } else { + return ParseConnectivityResult.none; + } + } + + // Test single connection types + expect(mapResult([ConnectivityResult.wifi]), + ParseConnectivityResult.wifi); + expect(mapResult([ConnectivityResult.ethernet]), + ParseConnectivityResult.ethernet); + expect(mapResult([ConnectivityResult.mobile]), + ParseConnectivityResult.mobile); + expect(mapResult([ConnectivityResult.none]), + ParseConnectivityResult.none); + + // Test priority when multiple connections exist + expect(mapResult([ConnectivityResult.wifi, ConnectivityResult.ethernet]), + ParseConnectivityResult.wifi); + expect(mapResult([ConnectivityResult.wifi, ConnectivityResult.mobile]), + ParseConnectivityResult.wifi); + expect( + mapResult([ConnectivityResult.ethernet, ConnectivityResult.mobile]), + ParseConnectivityResult.ethernet); + + // Test that ethernet takes priority over mobile (critical for issue #1042) + expect( + mapResult([ConnectivityResult.mobile, ConnectivityResult.ethernet]), + ParseConnectivityResult.ethernet); + + // Test fallback behavior for unsupported types + expect(mapResult([ConnectivityResult.bluetooth]), + ParseConnectivityResult.none); + expect(mapResult([ConnectivityResult.vpn]), ParseConnectivityResult.none); + expect( + mapResult([ConnectivityResult.other]), ParseConnectivityResult.none); + + // Test mixed with unsupported types + expect( + mapResult([ConnectivityResult.ethernet, ConnectivityResult.vpn]), + ParseConnectivityResult.ethernet); + }); + }); +}