-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ara Yapejian
committed
Oct 7, 2017
1 parent
037d15b
commit 087746d
Showing
12 changed files
with
522 additions
and
150 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"python.linting.pylintEnabled": false | ||
"python.linting.pylintEnabled": false, | ||
"mocha.enabled": true | ||
} |
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,36 @@ | ||
const should = require('should'); | ||
const nock = require('nock'); | ||
const smock = require('simple-mock'); | ||
const HaApi = require('../lib/ha-api'); | ||
|
||
const TEST_CONFIG = { | ||
baseUrl: 'http://bogus', | ||
apiPass: 'bogus' | ||
}; | ||
|
||
describe('HaApi Tests', function() { | ||
afterEach(function () { | ||
smock.restore(); | ||
}) | ||
|
||
describe('instantiation', function() { | ||
it('should instantiate correctly', function () { | ||
const haApi = new HaApi(TEST_CONFIG); | ||
|
||
haApi.config.should.equal(TEST_CONFIG); | ||
haApi.client.defaults.headers['x-ha-access'].should.equal(TEST_CONFIG.apiPass); | ||
haApi.client.defaults.baseURL.should.equal(`${TEST_CONFIG.baseUrl}/api`); | ||
}); | ||
}) | ||
|
||
describe('API Calls', function () { | ||
it('should get services', async function() { | ||
nock(TEST_CONFIG.baseUrl).get('/api/services').reply(200, 'testing'); | ||
|
||
const haApi = new HaApi(TEST_CONFIG); | ||
const services = await haApi.getServices(); | ||
services.should.equal('testing'); | ||
}) | ||
}) | ||
}); | ||
|
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,31 @@ | ||
require('should'); | ||
const smock = require('simple-mock'); | ||
const HaEvents = require('../lib/ha-events'); | ||
|
||
const TEST_CONFIG = { | ||
baseUrl: 'http://bogus', | ||
apiPass: 'bogus', | ||
events: { | ||
transport: 'sse', // For future support of websockets | ||
retries: { | ||
maxAttempts: 10, // How many times to retry connection | ||
delay: 5000 // Delay this long before retry (in ms) | ||
} | ||
} | ||
}; | ||
|
||
describe('HaEvents Tests', function() { | ||
afterEach(function () { | ||
smock.restore(); | ||
}) | ||
|
||
describe('instantiation', function() { | ||
it('should instantiate correctly', function () { | ||
const haEvents = new HaEvents(TEST_CONFIG); | ||
|
||
haEvents.config.should.equal(TEST_CONFIG); | ||
haEvents.streamUrl.should.equal(`${TEST_CONFIG.baseUrl}/api/stream`); | ||
}); | ||
}) | ||
}); | ||
|
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,36 @@ | ||
const should = require('should'); | ||
const nock = require('nock'); | ||
const smock = require('simple-mock'); | ||
const HomeAssistant = require('..'); | ||
|
||
describe('HomeAssistant Tests', function() { | ||
afterEach(function () { | ||
smock.restore(); | ||
}) | ||
|
||
it('should allow instantiation without config', async function () { | ||
const homeAssistant = await new HomeAssistant(); | ||
should.exist(homeAssistant); | ||
}); | ||
|
||
it('should automatically start listenting during instantiation if startListening === true', async function() { | ||
const homeAssistantExpected = {}; | ||
const startListeningProxy = smock.mock(HomeAssistant.prototype, 'startListening').resolveWith(homeAssistantExpected); | ||
|
||
const homeAssistant = await new HomeAssistant({ baseUrl: 'http://localhost:8123' }, { startListening: true }); | ||
should.exist(homeAssistant); | ||
startListeningProxy.callCount.should.equal(1); | ||
}); | ||
|
||
it('should test incorrect connection', async function() { | ||
const isValidConnection = await HomeAssistant.testConnection({ baseUrl: 'http://bogus' }); | ||
isValidConnection.should.equal(false); | ||
}); | ||
|
||
it('should test correct connection', async function() { | ||
nock('http://fakeHomeAssistant').get('/api/config').reply(200); | ||
|
||
const isValidConnection = await HomeAssistant.testConnection({ baseUrl: 'http://fakeHomeAssistant' }); | ||
isValidConnection.should.equal(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
'use strict'; | ||
module.exports = require('./lib/_index'); | ||
module.exports = require('./lib/node-home-assistant'); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.