@onekeyfe/hd-transport-react-native 1.2.0-alpha.66 → 1.2.0-alpha.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,132 +0,0 @@
1
- import { EventEmitter } from 'events';
2
-
3
- import { getConnectedDeviceIds } from '../BleManager';
4
- import ReactNativeBleTransport from '../index';
5
-
6
- jest.mock(
7
- 'react-native',
8
- () => ({
9
- PermissionsAndroid: {},
10
- Platform: { OS: 'ios' },
11
- }),
12
- { virtual: true }
13
- );
14
-
15
- jest.mock('react-native-ble-plx', () => ({
16
- BleError: class BleError extends Error {},
17
- BleErrorCode: {},
18
- BleManager: jest.fn(),
19
- ScanMode: { LowLatency: 2 },
20
- }));
21
-
22
- jest.mock('../BleManager', () => ({
23
- getConnectedDeviceIds: jest.fn(),
24
- onDeviceBondState: jest.fn(),
25
- pairDevice: jest.fn(),
26
- }));
27
-
28
- jest.mock('../subscribeBleOn', () => ({
29
- subscribeBleOn: jest.fn(() => Promise.resolve()),
30
- }));
31
-
32
- const ONEKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
33
-
34
- describe('ReactNativeBleTransport iOS discovery', () => {
35
- test('filters a bonded Pro2 Find My peripheral while keeping the wallet peripheral', async () => {
36
- jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([
37
- {
38
- id: 'find-my-peripheral',
39
- name: 'Pro2 6E9E - Find My',
40
- localName: null,
41
- serviceUUIDs: [ONEKEY_SERVICE_UUID],
42
- },
43
- {
44
- id: 'wallet-peripheral',
45
- name: 'Pro2 6E9E',
46
- localName: 'Pro2 6E9E',
47
- serviceUUIDs: [ONEKEY_SERVICE_UUID],
48
- },
49
- ] as never);
50
- const blePlxManager = {
51
- startDeviceScan: jest.fn(),
52
- stopDeviceScan: jest.fn(),
53
- };
54
- const transport = new ReactNativeBleTransport({ scanTimeout: 1 });
55
- transport.blePlxManager = blePlxManager as never;
56
- transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
57
-
58
- const devices = await transport.enumerate();
59
-
60
- expect(devices.map(device => device.id)).toEqual(['wallet-peripheral']);
61
- });
62
-
63
- test('filters a scanned Pro2 Find My peripheral by name when localName is null', async () => {
64
- jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([]);
65
- const blePlxManager = {
66
- startDeviceScan: jest.fn((_serviceUUIDs, _options, listener) => {
67
- queueMicrotask(() => {
68
- listener(null, {
69
- id: 'find-my-peripheral',
70
- name: 'Pro2 6E9E - Find My',
71
- localName: null,
72
- serviceUUIDs: [ONEKEY_SERVICE_UUID],
73
- });
74
- listener(null, {
75
- id: 'wallet-peripheral',
76
- name: 'Pro2 6E9E',
77
- localName: 'Pro2 6E9E',
78
- serviceUUIDs: [ONEKEY_SERVICE_UUID],
79
- });
80
- });
81
- }),
82
- stopDeviceScan: jest.fn(),
83
- };
84
- const transport = new ReactNativeBleTransport({ scanTimeout: 1 });
85
- transport.blePlxManager = blePlxManager as never;
86
- transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
87
-
88
- const devices = await transport.enumerate();
89
-
90
- expect(devices.map(device => device.id)).toEqual(['wallet-peripheral']);
91
- });
92
-
93
- test('ignores an unnamed scanned advertisement while keeping the named wallet peripheral', async () => {
94
- jest.mocked(getConnectedDeviceIds).mockResolvedValueOnce([]);
95
- const blePlxManager = {
96
- startDeviceScan: jest.fn((_serviceUUIDs, _options, listener) => {
97
- queueMicrotask(() => {
98
- listener(null, {
99
- id: 'unnamed-peripheral',
100
- name: null,
101
- localName: null,
102
- serviceUUIDs: [
103
- '0000180a-0000-1000-8000-00805f9b34fb',
104
- '0000180f-0000-1000-8000-00805f9b34fb',
105
- '0000fffd-0000-1000-8000-00805f9b34fb',
106
- ONEKEY_SERVICE_UUID,
107
- ],
108
- });
109
- listener(null, {
110
- id: 'wallet-peripheral',
111
- name: 'Pro2 769D',
112
- localName: 'Pro2 769D',
113
- serviceUUIDs: [
114
- '0000180a-0000-1000-8000-00805f9b34fb',
115
- '0000180f-0000-1000-8000-00805f9b34fb',
116
- '0000fffd-0000-1000-8000-00805f9b34fb',
117
- ONEKEY_SERVICE_UUID,
118
- ],
119
- });
120
- });
121
- }),
122
- stopDeviceScan: jest.fn(),
123
- };
124
- const transport = new ReactNativeBleTransport({ scanTimeout: 1 });
125
- transport.blePlxManager = blePlxManager as never;
126
- transport.init({ debug: jest.fn(), error: jest.fn() }, new EventEmitter());
127
-
128
- const devices = await transport.enumerate();
129
-
130
- expect(devices.map(device => device.id)).toEqual(['wallet-peripheral']);
131
- });
132
- });