-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for the HueAPIConfig to eliminate typo issues as identif…
…ied in #155.
- Loading branch information
1 parent
d45f101
commit f40492d
Showing
2 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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'); | ||
} | ||
}); | ||
}); | ||
}); |