diff --git a/functions/config.js b/functions/config.js index 5da71776..4ec6fbe9 100644 --- a/functions/config.js +++ b/functions/config.js @@ -33,8 +33,8 @@ * **/ module.exports = { - //userpass: 'user@foo.com:Password1', - host: '', - port: 443, - path: '/YOUR/REST/ENDPOINT' + //userpass: process.env.OH_USERPASS || 'user@foo.com:Password1', + host: process.env.OH_HOST || '', + port: process.env.OH_PORT || 443, + path: process.env.OH_PATH || '/YOUR/REST/ENDPOINT' }; diff --git a/package.json b/package.json index 94486727..8eb522d7 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,11 @@ "release-minor": "npm version minor -m \":bookmark: Release (minor): %s\"", "release-patch": "npm version patch -m \":bookmark: Release (patch): %s\"" }, + "jest": { + "setupFiles": [ + "./tests/setenv.js" + ] + }, "license": "EPL-2.0", "bugs": { "url": "https://github.com/openhab/openhab-google-assistant/issues" diff --git a/testServer.js b/testServer.js index 5cc0a022..357c5b2d 100644 --- a/testServer.js +++ b/testServer.js @@ -8,6 +8,7 @@ app.use('/', (req, res) => { openhabGA.openhabGoogleAssistant(req, res); }); -app.listen(3000, () => { - console.log('Server is listening on port 3000'); +const port = process.env.OH_SERVER_PORT || 3000; +app.listen(port, () => { + console.log('Server is listening on port %s', port); }); diff --git a/tests/config.test.js b/tests/config.test.js index 44af12c5..2f2a4968 100644 --- a/tests/config.test.js +++ b/tests/config.test.js @@ -1,7 +1,13 @@ const Config = require('../functions/config.js'); describe('Config', () => { - test('Config all properties', () => { + test('All properties available', () => { expect(Object.keys(Config)).toStrictEqual(['host', 'port', 'path']); }); + + test('Properties used from ENV', () => { + expect(Config.host).toBe('test.host'); + expect(Config.port).toBe('1234'); + expect(Config.path).toBe('/test/items'); + }); }); diff --git a/tests/setenv.js b/tests/setenv.js new file mode 100644 index 00000000..2b97d385 --- /dev/null +++ b/tests/setenv.js @@ -0,0 +1,3 @@ +process.env.OH_HOST = 'test.host'; +process.env.OH_PORT = '1234'; +process.env.OH_PATH = '/test/items';