Skip to content

Commit

Permalink
✅ Add test for getDeviceDataTypeByBluetoothId with anonymous ios uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte2036 committed May 29, 2024
1 parent ab576de commit 0600c4c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/src/ftms_bluetooth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ class FTMSBluetooth {
}

static DeviceDataType? getDeviceDataTypeByBluetoothId(String id) {
if (id.length != 17) {
// no valid mac address
return null;
}

var data = List<int>.from(id
.split(":")
.getRange(4, 6)
Expand Down
27 changes: 24 additions & 3 deletions test/ftms_bluetooth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@ import 'ftms_bluetooth_test.mocks.dart';
// generate mock files: dart run build_runner build
@GenerateMocks([BluetoothDevice, BluetoothService, BluetoothCharacteristic])
void main() {
test("test getDeviceDataTypeByBluetoothId", () {
var res = FTMSBluetooth.getDeviceDataTypeByBluetoothId("22:22:A4:A6:02:00");
expect(res, DeviceDataType.crossTrainer);
group("test getDeviceDataTypeByBluetoothId", () {
test("test getDeviceDataTypeByBluetoothId with treadmill mac address", () {
var res =
FTMSBluetooth.getDeviceDataTypeByBluetoothId("22:22:A4:A6:02:00");
expect(res, DeviceDataType.crossTrainer);
});

test("test getDeviceDataTypeByBluetoothId with unkown mac address", () {
var res =
FTMSBluetooth.getDeviceDataTypeByBluetoothId("22:22:A4:A6:00:00");
expect(res, null);
});

test("test getDeviceDataTypeByBluetoothId with invalid mac address", () {
var res = FTMSBluetooth.getDeviceDataTypeByBluetoothId("invalid");
expect(res, null);
});

// see https://github.com/Malte2036/flutter_ftms/issues/14
test("test getDeviceDataTypeByBluetoothId with anonymous ios uuid", () {
var res = FTMSBluetooth.getDeviceDataTypeByBluetoothId(
"6920a902-ba0e-4a13-a35f-6bc91161c517");
expect(res, null);
});
});

group("test getFTMSService", () {
Expand Down

0 comments on commit 0600c4c

Please sign in to comment.