-
Notifications
You must be signed in to change notification settings - Fork 557
Expand file tree
/
Copy pathService.js
More file actions
60 lines (51 loc) · 2.35 KB
/
Service.js
File metadata and controls
60 lines (51 loc) · 2.35 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
56
57
58
59
60
jest.mock('../src/BleManager')
const { BleManager } = require('../src/BleManager')
const { Service } = require('../src/Service')
describe("Test if Service is properly calling BleManager's utility function:", () => {
const bleManager = new BleManager()
const service = new Service({ id: 'serviceId', uuid: 'serviceUUID', deviceID: 'deviceId' }, bleManager)
test('characteristics', async () => {
await service.characteristics()
expect(bleManager._characteristicsForService).toBeCalledWith('serviceId')
})
test('descriptorsForCharacteristic', async () => {
await service.descriptorsForCharacteristic('characteristicUUID')
expect(bleManager._descriptorsForService).toBeCalledWith('serviceId', 'characteristicUUID')
})
test('readCharacteristic', async () => {
await service.readCharacteristic('bbbb', 'id')
expect(bleManager._readCharacteristicForService).toBeCalledWith('serviceId', 'bbbb', 'id')
})
test('writeCharacteristicWithResponse', async () => {
await service.writeCharacteristicWithResponse('bbbb', 'value', 'id')
expect(bleManager._writeCharacteristicWithResponseForService).toBeCalledWith('serviceId', 'bbbb', 'value', 'id')
})
test('writeCharacteristicWithoutResponse', async () => {
await service.writeCharacteristicWithoutResponse('bbbb', 'value', 'id')
expect(bleManager._writeCharacteristicWithoutResponseForService).toBeCalledWith('serviceId', 'bbbb', 'value', 'id')
})
test('monitorCharacteristic', async () => {
const listener = jest.fn()
await service.monitorCharacteristic('bbbb', listener, 'id')
expect(bleManager._monitorCharacteristicForService).toBeCalledWith('serviceId', 'bbbb', listener, 'id')
})
test('readDescriptorForCharacteristic', async () => {
await service.readDescriptorForCharacteristic('characteristicUUID', 'descriptorUUID', 'transactionId')
expect(bleManager._readDescriptorForService).toBeCalledWith(
'serviceId',
'characteristicUUID',
'descriptorUUID',
'transactionId'
)
})
test('writeDescriptorForCharacteristic', async () => {
await service.writeDescriptorForCharacteristic('characteristicUUID', 'descriptorUUID', 'value', 'transactionId')
expect(bleManager._writeDescriptorForService).toBeCalledWith(
'serviceId',
'characteristicUUID',
'descriptorUUID',
'value',
'transactionId'
)
})
})