/* eslint-env mocha */
/* eslint no-unused-expressions: ["off"] */

'use strict';

const chai = require('chai');
const expect = chai.expect;

const Device = require('..').Device;

describe('Device', function () {
  describe('constructor()', function () {
    it('accept options', function () {
      var opt = {model: 'hs100', port: 1234, address: '127.0.0.1', data: {'deviceId': 'ABC'}};
      let device = new Device(opt);
      expect(device).to.have.property('model', opt.model);
      expect(device).to.have.property('port', opt.port);
      expect(device).to.have.property('address', opt.address);
      expect(device).to.have.property('data', opt.data);
      expect(device.api).to.exist;
    });
    it('defaults', function () {
      let device = new Device({model: 'hs100'});
      expect(device).to.have.property('port', 0);
      expect(device).to.have.property('address', '0.0.0.0');
      expect(device).to.have.property('data', undefined);
      expect(device.api).to.exist;
    });
    it('throw if no model', function () {
      expect(() => { new Device(); }).to.throw(); // eslint-disable-line no-new
    });
    it('throw if invalid model', function () {
      expect(() => { new Device({model: 'invalid_model'}); }).to.throw();// eslint-disable-line no-new
    });

    Device.models.forEach((model) => {
      describe(model, function () {
        it('has api', function () {
          let device = new Device({model});
          expect(device.api).to.exist;
        });
      });
    });
  });
});

@@ -618,32 +618,39 @@
 device).to.have.
+nested.
 property('data',
@@ -647,16 +647,25 @@
 ty('data
+.deviceId
 ', opt.d
@@ -667,16 +667,25 @@
 opt.data
+.deviceId
 );%0A     
@@ -936,32 +936,37 @@
 device).to.have.
+deep.
 property('data',
@@ -970,17 +970,24 @@
 a', 
-undefined
+%7Bmodel: 'hs100'%7D
 );%0A 
@@ -1356,16 +1356,113 @@
 l) =%3E %7B%0A
+      let device;%0A      beforeEach(function () %7B%0A        device = new Device(%7Bmodel%7D);%0A      %7D);%0A
       de
@@ -1529,52 +1529,8 @@
 ) %7B%0A
-          let device = new Device(%7Bmodel%7D);%0A
     
@@ -1572,24 +1572,24 @@
         %7D);%0A
-
       %7D);%0A  
@@ -1599,13 +1599,993 @@
 );%0A  %7D);
+%0A%0A  let device;%0A  beforeEach(function () %7B%0A    device = new Device(%7Bmodel: 'hs100'%7D);%0A  %7D);%0A%0A  describe('#start()', function () %7B%0A    before(function () %7B%0A      this.timeout = 5000;%0A    %7D);%0A%0A    it('should open server / sockets', async function () %7B%0A      await device.start();%0A      expect(device.udpSocketBound).to.be.true;%0A      expect(device.serverBound).to.be.true;%0A      return device.stop();%0A    %7D);%0A  %7D);%0A%0A  describe('#stop()', function () %7B%0A    before(function () %7B%0A      this.timeout = 5000;%0A    %7D);%0A    it('should close server / sockets', async function () %7B%0A      await device.start();%0A      await device.stop();%0A      expect(device.udpSocketBound).to.be.false;%0A      expect(device.serverBound).to.be.false;%0A    %7D);%0A    it('does nothing when stopped twice', async function () %7B%0A      await device.start();%0A      await device.stop();%0A      return device.stop();%0A    %7D);%0A    it('does nothing if not started', async function () %7B%0A      return device.stop();%0A    %7D);%0A  %7D);
 %0A%7D);%0A

add tests for start/stop