From dbbbe3fff5f98e3732a9068c8dd835d83b82d02e Mon Sep 17 00:00:00 2001 From: cse47122 Date: Fri, 25 Dec 2020 15:47:25 +0000 Subject: [PATCH] Delete 'fake-device.js' --- fake-device.js | 81 -------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 fake-device.js diff --git a/fake-device.js b/fake-device.js deleted file mode 100644 index 8d01581..0000000 --- a/fake-device.js +++ /dev/null @@ -1,81 +0,0 @@ -/* globals describe it */ - -const expect = require('chai').expect - -const FakeDevice = require('../src/fake-device') -const measurements = { - usage: {type: 'integer', min: 0, max: 100}, - voltage: {type: 'integer', min: 0, max: 15}, - temperature: {type: 'integer', min: -20, max: 60} -} - -// create fake influx connection -let connectionWriteData = false -const connection = { - send: (deviceId, data) => { - return new Promise((resolve, reject) => { - connectionWriteData = {deviceId, data} - resolve() - }) - } -} - -describe('FakeDevice', function () { - let fakeDevice = null - - it('should throw error if no params are passed', function () { - expect(FakeDevice).to.throw(Error) - }) - - it('shold throw missing deviceId param', function () { - expect(() => FakeDevice({})).to.throw('Missing deviceId param') - }) - - it('shold throw missing connection param', function () { - expect(() => FakeDevice({ - deviceId: 1 - })).to.throw('Missing connection param') - }) - - it('shold throw missing measurements param', function () { - expect(() => FakeDevice({ - deviceId: 1, - connection - })).to.throw('Missing measurements param') - }) - - it('should create instance', function () { - fakeDevice = FakeDevice({ - deviceId: 1, - connection, - sendInterval: 1000, - measurements - }) - expect(fakeDevice).to.have.property('start') - }) - - it('should generate data', function (done) { - fakeDevice.start() - setTimeout(() => { - let data = fakeDevice.getData() - done(!data.length) - }, 500) - }) - - it('should send data to influx', function (done) { - setTimeout(() => { - if (!connectionWriteData) return done('No data') - if (!connectionWriteData.deviceId) return done('Invalid write data - missing deviceId') - if ( - connectionWriteData.data[0].usage && - connectionWriteData.data[0].voltage && - connectionWriteData.data[0].temperature && - connectionWriteData.data[0].timestamp - ) { - done() - } else { - done('Invalid write data format') - } - }, 1000) - }) -})