HueApiConfig.test.js
2.48 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
'use strict';
const expect = require('chai').expect
, HueApiConfig = require('./HueApiConfig')
, Transport = require('./http/Transport')
, RemoteApi = require('./http/RemoteApi')
, ApiError = require('../ApiError')
;
const BASE_URL = 'https://localhost:443'
, DUMMY_CLIENT_KEY = 'aaaaaaaaaaaaaaaaaa'
, DUMMY_CLIENT_SECRET = 'abcd1234567890'
, DUMMY_CLIENT_ID = 'abcd1234567890abc'
, USERNAME = 'xxxxxxxxxxxxxxxxxxxx'
;
describe('HueApiConfig', () => {
const dummyTransport = new Transport(null, null, null);
describe('Remote API', () => {
const dummyRemoteApi = new RemoteApi(null, null);
let config;
beforeEach(() => {
config = new HueApiConfig({
remote: true,
username: USERNAME,
baseUrl: BASE_URL,
clientSecret: DUMMY_CLIENT_SECRET,
clientId: DUMMY_CLIENT_ID
},
dummyTransport,
dummyRemoteApi
);
});
it('should get #baseURL', () => {
expect(config.baseUrl).to.equal(BASE_URL);
});
it('should get #username', () => {
expect(config.username).to.equal(USERNAME);
});
it('should identify a remote API', () => {
expect(config.isRemote).to.be.true;
expect(config.transport).to.equal(dummyTransport);
expect(config.remote).to.equal(dummyRemoteApi);
});
it('should get #clientSecret and #clientId', () => {
expect(config.clientSecret).to.equal(DUMMY_CLIENT_SECRET);
expect(config.clientId).to.equal(DUMMY_CLIENT_ID);
});
it('should fail on #clientKey', () => {
try {
config.clientKey;
} catch (err) {
expect(err.message).to.contain('only valid on a local Hue API instance');
}
});
});
describe('Local API', () => {
let config;
beforeEach(() => {
config = new HueApiConfig({
baseUrl: BASE_URL,
username: USERNAME,
clientkey: DUMMY_CLIENT_KEY,
},
dummyTransport);
});
it('should get #baseURL', () => {
expect(config.baseUrl).to.equal(BASE_URL);
});
it('should get #username', () => {
expect(config.username).to.equal(USERNAME);
});
it('should get #clientKey', () => {
expect(config.clientKey).to.equal(DUMMY_CLIENT_KEY);
});
it('should error on #remote', () => {
try {
config.remote;
} catch (err) {
expect(err).to.be.instanceOf(ApiError);
expect(err.message).to.contain('not been set up as a remote API');
}
});
});
});