forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbt_device_from_json_test.dart
More file actions
55 lines (51 loc) · 1.86 KB
/
Copy pathbt_device_from_json_test.dart
File metadata and controls
55 lines (51 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/backend/schema/bt_device/bt_device.dart';
void main() {
test('every device type has a stable analytics vendor', () {
expect(
{for (final type in DeviceType.values) type: type.analyticsVendor},
{
DeviceType.omi: 'omi',
DeviceType.openglass: 'omi',
DeviceType.appleWatch: 'apple',
DeviceType.plaud: 'plaud',
DeviceType.bee: 'bee',
DeviceType.fieldy: 'fieldlabs',
DeviceType.friendPendant: 'friend',
DeviceType.limitless: 'limitless',
DeviceType.raybanMeta: 'meta',
},
);
});
group('BtDevice.fromJson', () {
test('parses a well-formed json round-trip', () {
final device = BtDevice(id: 'AA:BB:CC', name: 'Omi', type: DeviceType.omi, rssi: -60);
final restored = BtDevice.fromJson(device.toJson());
expect(restored.id, 'AA:BB:CC');
expect(restored.name, 'Omi');
expect(restored.type, DeviceType.omi);
expect(restored.rssi, -60);
});
// Regression: Crashlytics f47896e23d3d0823 — persisted rssi stored as a
// String crashed fromJson with "type 'String' is not a subtype of type 'int'".
test('does not throw when rssi is persisted as a String', () {
final restored = BtDevice.fromJson({'name': 'Omi', 'id': 'AA:BB:CC', 'type': 'omi', 'rssi': '-60'});
expect(restored.rssi, -60);
});
test('falls back to safe defaults for missing or mistyped fields', () {
final restored = BtDevice.fromJson({
'name': null,
'id': 42,
'type': 'omi',
'rssi': 'garbage',
'locator': 'not-a-map',
'modelNumber': 1,
});
expect(restored.name, '');
expect(restored.id, '');
expect(restored.rssi, 0);
expect(restored.locator, isNull);
expect(restored.modelNumber, 'Unknown');
});
});
}