bridge-validation.test.js
5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict';
const expect = require('chai').expect
, bridgeValidation = require('./bridge-validation')
, textValues = require('../../../test/support/testValues')
;
describe('bridge-validation', () => {
describe('#parseXmlDescription()', () => {
it('should extract description from XML', () => {
const data = '<root xmlns="urn:schemas-upnp-org:device-1-0">\n' +
'<specVersion>\n' +
'<major>1</major>\n' +
'<minor>0</minor>\n' +
'</specVersion>\n' +
'<URLBase>https://192.168.1.130:80/</URLBase>\n' +
'<device>\n' +
'<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>\n' +
'<friendlyName>Philips hue (192.168.1.130)</friendlyName>\n' +
'<manufacturer>Royal Philips Electronics</manufacturer><manufacturerURL>https://www.philips.com</manufacturerURL>\n' +
'<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>\n' +
'<modelName>Philips hue bridge 2012</modelName>\n' +
'<modelNumber>929000226503</modelNumber>\n' +
'<modelURL>https://www.meethue.com</modelURL>\n' +
'<serialNumber>001788102201</serialNumber>\n' +
'<UDN>uuid:2f402f80-da50-11e1-9b23-001788102201</UDN>\n' +
'<presentationURL>index.html</presentationURL>\n' +
'<iconList>\n' +
'<icon>\n' +
'<mimetype>image/png</mimetype>\n' +
'<height>48</height>\n' +
'<width>48</width>\n' +
'<depth>24</depth>\n' +
'<url>hue_logo_0.png</url>\n' +
'</icon>\n' +
'<icon>\n' +
'<mimetype>image/png</mimetype>\n' +
'<height>120</height>\n' +
'<width>120</width>\n' +
'<depth>24</depth>\n' +
'<url>hue_logo_3.png</url>\n' +
'</icon>\n' +
'</iconList>\n' +
'</device>\n' +
'</root>';
const result = bridgeValidation.parseXmlDescription(data);
expect(result).to.have.property('name').to.equal('Philips hue (192.168.1.130)');
expect(result).to.have.property('manufacturer').to.equal('Royal Philips Electronics');
expect(result).to.have.property('ipaddress').to.equal('192.168.1.130');
expect(result).to.have.property('model');
expect(result.model).to.have.property('number').to.equal('929000226503');
expect(result.model).to.have.property('description').to.equal('Philips hue Personal Wireless Lighting');
expect(result.model).to.have.property('name').to.equal('Philips hue bridge 2012');
expect(result.model).to.have.property('serial').to.equal('001788102201');
expect(result).to.have.property('icons');
expect(result.icons).to.be.instanceOf(Array);
expect(result.icons[0]).to.have.property('mimetype').to.equal('image/png');
expect(result.icons[0]).to.have.property('height').to.equal('48');
expect(result.icons[0]).to.have.property('width').to.equal('48');
expect(result.icons[0]).to.have.property('depth').to.equal('24');
expect(result.icons[0]).to.have.property('url').to.equal('hue_logo_0.png');
expect(result.icons[1]).to.have.property('mimetype').to.equal('image/png');
expect(result.icons[1]).to.have.property('height').to.equal('120');
expect(result.icons[1]).to.have.property('width').to.equal('120');
expect(result.icons[1]).to.have.property('depth').to.equal('24');
expect(result.icons[1]).to.have.property('url').to.equal('hue_logo_3.png');
});
});
describe('#getBridgeConfig()', () => {
it('should get config on a valid bridge', async () => {
const ipAddress = '192.168.10.40'; //TODO hard coded
const config = await bridgeValidation.getBridgeConfig({internalipaddress: ipAddress}, 5000);
expect(config).to.have.property('name').to.equal('Philips hue');
expect(config).to.have.property('ipaddress').to.equal(ipAddress);
expect(config).to.have.property('modelid');
expect(config).to.have.property('swversion');
});
it('should fail for invalid ip address', async function() {
const ipAddress = '10.0.0.1'
, timeout = 2000
;
// Make test time out double that of the actual timeout on the request
this.timeout(timeout * 2);
try {
await bridgeValidation.getBridgeConfig({internalipaddress: ipAddress}, timeout);
expect.fail('Should have failed');
} catch (err) {
expect(err.message).to.contain('network timeout');
}
});
});
describe('#getBridgeDescription()', () => {
it('should get config on a valid bridge', async () => {
const ipAddress = '192.168.10.40'; //TODO hard coded
const config = await bridgeValidation.getBridgeDescription({internalipaddress: ipAddress}, 5000);
expect(config).to.have.property('name').to.include('Philips hue');
expect(config).to.have.property('ipaddress').to.equal(ipAddress);
expect(config).to.have.property('model');
expect(config.model).to.have.property('number').to.equal('BSB002');
expect(config.model).to.have.property('name');
expect(config.model).to.have.property('description');
});
it('should fail for invalid ip address', async function() {
const ipAddress = '10.0.0.1'
, timeout = 2000
;
// Make test time out double that of the actual timeout on the request
this.timeout(timeout * 2);
try {
await bridgeValidation.getBridgeDescription({internalipaddress: ipAddress}, timeout);
expect.fail('Should have failed');
} catch (err) {
expect(err.message).to.contain('network timeout');
}
});
});
});