diff --git a/src/peripheral/bleno/characteristic.test.js b/src/peripheral/bleno/characteristic.test.js index c3867c9..09989c1 100644 --- a/src/peripheral/bleno/characteristic.test.js +++ b/src/peripheral/bleno/characteristic.test.js @@ -81,6 +81,8 @@ test('Characteristic.onUnsubscribe', () => { test('Characteristic.updateState', () => { const characteristic = Characteristic('mockUUID', Parent, util, 'mockDescriptor', { encode, decode }); + characteristic.updateState({ mockState: 'mockState' }); + const maxValueSize = 10; const updateValueCallback = jest.fn(); characteristic.onSubscribe(maxValueSize, updateValueCallback); diff --git a/src/webapp/actions/actions.test.js b/src/webapp/actions/actions.test.js index fae57de..0e08ed6 100644 --- a/src/webapp/actions/actions.test.js +++ b/src/webapp/actions/actions.test.js @@ -10,7 +10,6 @@ beforeEach(() => { central = { connect: jest.fn().mockReturnValue(Promise.resolve()), handler: jest.fn(), - read: jest.fn().mockReturnValue(Promise.resolve('mockState')), write: jest.fn().mockReturnValue(Promise.resolve()), }; }); diff --git a/src/webapp/central/central.js b/src/webapp/central/central.js index bad0ab7..b35af3f 100644 --- a/src/webapp/central/central.js +++ b/src/webapp/central/central.js @@ -39,13 +39,6 @@ export default function Central( return listerner; }); - const read = () => { - if (state.server && state.server.connected && state.characteristic) { - return state.characteristic.readValue().then(data => decode(data)); - } - return Promise.reject(new Error('Bluetooth: Not Connected')); - }; - const write = (action) => { if (!state.server || !state.server.connected || !state.characteristic) return null; const stringify = JSON.stringify(action); @@ -58,7 +51,6 @@ export default function Central( connected: state.server && state.server.connected, connect, handler, - read, write, }; } diff --git a/src/webapp/central/central.test.js b/src/webapp/central/central.test.js index 48d974c..7c11f76 100644 --- a/src/webapp/central/central.test.js +++ b/src/webapp/central/central.test.js @@ -73,16 +73,22 @@ test('Central: handler', () => { return expect(promise).resolves.toBe(true); }); -test('Central: read', () => { - expect.assertions(2); +test('Central: handler chunk', () => { + const callback = jest.fn(); + expect.assertions(3); - const promise = central.connect('mockName').then(() => central.read()) - .then((data) => { - expect(characteristic.readValue).toBeCalled(); - return data; + encoder.decode = jest.fn().mockReturnValue('{"mockDecode":"mockDecode"}'); + central = new Central(bluetooth, encoder, CENTRAL_CONFIG); + + const promise = central.connect('mockName').then(() => central.handler(callback)) + .then((listerner) => { + expect(characteristic.startNotifications).toBeCalled(); + listerner({ target: { value: 'mockEvent' } }); + expect(callback.mock.calls.length).toEqual(0); + return true; }); - return expect(promise).resolves.toBe('[[[{"mockDecode":"mockDecode"}]]]'); + return expect(promise).resolves.toBe(true); }); test('Central: write', () => {