it('should trigger the reading of the latest tick in order to have an initial reference for the log', function() { log.downloadLog(); expect(device.sendRead).toHaveBeenCalled(); expect(device.buffers[3]).toEqual(new Buffer([0xb,0x84])); });
describe('subscribe()', function() { it('should subscribe to the magnetometer notification', function() { magnetometer.subscribe(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x15,0x5,0x1])); }); });
it('should trigger the log READOUT specifying the correct number of entries to be notified for 0.05 notification progress', function() { var data = new Buffer([0x68,0x8,0x0,0x0]); log.downloadLog(); expect(device.send.calls.any()).toBe(true); device.send.calls.reset(); device.emitter.emit([MODULE, LENGTH], data, MODULE.toString(16), LENGTH.toString(16)); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0xb,0x6,0x68,0x8,0x0,0x0,0x6b,0x0,0x0,0x0])); });
describe('Settings', function() { var device = new Device(), settings = new Settings(device); describe('setConnectionParameter(...)', function() { beforeEach(function() { spyOn(device, 'send').and.callThrough(); jasmine.addCustomEqualityTester(bufferEqual); }); it('should send the correct connection parameters to the device', function() { settings.setConnectionParameters(750.0, 1000.0, 128, 16384); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x11, 0x09, 0x58, 0x02, 0x20, 0x03, 0x80, 0x00, 0x66, 0x06])); }); }); });
describe('setPreset', function() { it('should send the right preset recommended by Bosh for the BMM150 magnetometer to the device', function() { for(var i = 0; i< presets.length; i++) { magnetometer.setPreset(presets[i].preset); expect(device.send).toHaveBeenCalled(); expect(device.buffers[0]).toEqual(presets[i].expected[0]); expect(device.buffers[1]).toEqual(presets[i].expected[1]); device.reset(); } }); });
describe("Accelerometer", function() { var device = new Device(), accelerometer = new Accelerometer(device); it("should have 50hz as default value for output data rate", function() { expect(accelerometer.dataRate).toEqual(0x7); }); it("should have +-2g as default axis sampling range", function() { expect(accelerometer.accRange).toEqual([0x3, 16384]); }); describe("setConfig()", function() { beforeEach(function() { spyOn(device, 'send').and.callThrough(); jasmine.addCustomEqualityTester(bufferEqual); }); it("should send the default configured output data rate and axis sampling range to the MetaWear device", function() { accelerometer.setConfig(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x3,0x3,0x27,0x3])); }); }); });
it('with a specific error code', function () { let response = sut.buildErrorResponseEvent(event, error, 404); expect(sut.buildResponseEvent).toHaveBeenCalled(); expect(sut.getMethodFromEvent).toHaveBeenCalled(); expect(sut.getResourceUrlFromEvent).toHaveBeenCalled(); expect(response).toBeDefined(); expect(response.statusCode).toBe(500); it('with a default error code', function () { let response = sut.buildErrorResponseEvent(event, error); expect(sut.buildResponseEvent).toHaveBeenCalled(); expect(sut.getMethodFromEvent).toHaveBeenCalled(); expect(sut.getResourceUrlFromEvent).toHaveBeenCalled(); expect(response).toBeDefined(); expect(response.statusCode).toBe(500);
expect(device.send).toHaveBeenCalled();
describe('buildSuccessResponseEvent', function () { const event = { body: 'Event body' }; let result = { message: 'success' }; beforeEach(function () { spyOn(sut, 'buildResponseEvent').and.returnValue({ statusCode: 200, body: JSON.stringify(result) }); }); describe('returns a response event', function () { it('with a specific error code', function () { let response = sut.buildSuccessResponseEvent(event, result, 201); expect(sut.buildResponseEvent).toHaveBeenCalled(); expect(response).toBeDefined(); expect(response.statusCode).toBe(200); expect(response.body).toBeDefined(); }); it('with a default error code', function () { let response = sut.buildSuccessResponseEvent(event, result); expect(sut.buildResponseEvent).toHaveBeenCalled(); expect(response).toBeDefined(); expect(response.statusCode).toBe(200); expect(response.body).toBeDefined(); }); }); });
describe('disableAxisSampling()', function() { it('should disable sampling on the magnetometer', function() { magnetometer.disableAxisSampling(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x15,0x2,0x0,0x1])); }); });
describe('stop()', function() { it('should power off the magnetometer', function() { magnetometer.stop(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x15,0x1,0x0])); }); });
describe('enableAxisSampling()', function() { it('should enable sampling on the magnetometer', function() { magnetometer.enableAxisSampling(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x15,0x2,0x1,0x0])); }); });
describe('start()', function() { it('should power on the magnetometer', function() { magnetometer.start(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x15,0x1,0x1])); }); });
describe('unsubscribe()', function() { it('should unsubscribe to the magnetometer notification', function() { magnetometer.unsubscribe(); expect(device.send).toHaveBeenCalled(); expect(device.buffers.pop()).toEqual(new Buffer([0x15,0x5,0x0])); }); });
it('should trigger the reading the length of the log', function() { log.downloadLog(); expect(device.sendRead).toHaveBeenCalled(); expect(device.buffers[4]).toEqual(new Buffer([0xb,0x85])); });