Skip to content

Commit 16eacc1

Browse files
author
QuickSander
committed
feat(): Added unittests for informationService retrieval.
1 parent ee40516 commit 16eacc1

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// ISC License - Copyright 2018, Sander van Woensel
2+
13
// -----------------------------------------------------------------------------
24
// Constants
35
// -----------------------------------------------------------------------------
46
const PACKAGE_JSON = require('./package.json');
5-
const MANUFACTURER = PACKAGE_JSON.author.name bla bla'Sander van Woensel';
6-
const MODEL = PACKAGE_JSON.name;
7+
const MANUFACTURER = PACKAGE_JSON.author.name;
78
const SERIAL_NUMBER = '001';
9+
const MODEL = PACKAGE_JSON.name;
810
const FIRMWARE_REVISION = PACKAGE_JSON.version;
911

1012
// -----------------------------------------------------------------------------

test/basics.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ISC License - Copyright 2018, Sander van Woensel
2+
13
var expect = require('chai').expect;
24
var sinon = require('sinon');
35
var sut = require('../index.js');
@@ -184,3 +186,36 @@ describe('Get power state', function () {
184186
});
185187

186188
});
189+
190+
191+
// -----------------------------------------------------------------------------
192+
describe('Get services', function () {
193+
194+
beforeEach(function () {
195+
// 1. Arrange
196+
this.testConfig = new TestConfig();
197+
198+
// This will also make sure to reset the embedded Sinon stubs.
199+
this.homebridgeStub = new (require('./homebridge.stub.js'))(this.testConfig);
200+
sut(this.homebridgeStub);
201+
202+
203+
});
204+
205+
it('contains model, manufacturer, serial number and firmware revision sourced from package.json', function() {
206+
// 1. Arrange
207+
const PACKAGE = require('../package.json');
208+
209+
// 2. Act
210+
var services = this.homebridgeStub.accessory.getServices();
211+
212+
// 3. Assert
213+
expect(services[0].setCharacteristic.firstCall.lastArg).to.equal(PACKAGE.author.name);
214+
expect(services[0].setCharacteristic.secondCall.lastArg).to.equal("001");
215+
expect(services[0].setCharacteristic.thirdCall.lastArg).to.equal(PACKAGE.name);
216+
expect(services[0].setCharacteristic.lastCall.lastArg).to.equal(PACKAGE.version);
217+
});
218+
219+
220+
221+
});

test/homebridge.stub.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ISC License - Copyright 2018, Sander van Woensel
2+
13
var sinon = require('sinon');
24

35
//! Homebridge stub.
@@ -7,8 +9,24 @@ module.exports = function(config) {
79
this.logger = sinon.stub();
810

911
this.hap = {
10-
Service: null,
11-
Characteristic: null
12+
Service: {
13+
AccessoryInformation: function() {
14+
this.setCharacteristic = sinon.stub().returnsThis();
15+
},
16+
Lightbulb: function() {
17+
this.getCharacteristic = sinon.stub().returnsThis();
18+
this.on = sinon.stub().returnsThis();
19+
this.addCharacteristic = sinon.stub().returnsThis();
20+
}
21+
},
22+
23+
Characteristic: {
24+
Manufacturer: 0, SerialNumber: 1, Model: 2, FirmwareRevision: 3,
25+
On: 4,
26+
Hue: sinon.stub(),
27+
Saturation: sinon.stub(),
28+
Brightness: sinon.stub()
29+
}
1230
};
1331

1432
//! Construct and store accessory for access during test.

0 commit comments

Comments
 (0)