Skip to content

Commit

Permalink
Use config from ENV
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Krug <[email protected]>
  • Loading branch information
michikrug committed Apr 8, 2021
1 parent 4536d67 commit 0aa7186
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 4 additions & 4 deletions functions/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
*
**/
module.exports = {
//userpass: '[email protected]:Password1',
host: '<YOUR-CLOUD-HOST>',
port: 443,
path: '/YOUR/REST/ENDPOINT'
//userpass: process.env.OH_USERPASS || '[email protected]:Password1',
host: process.env.OH_HOST || '<YOUR-CLOUD-HOST>',
port: process.env.OH_PORT || 443,
path: process.env.OH_PATH || '/YOUR/REST/ENDPOINT'
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions testServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
8 changes: 7 additions & 1 deletion tests/config.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
3 changes: 3 additions & 0 deletions tests/setenv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.env.OH_HOST = 'test.host';
process.env.OH_PORT = '1234';
process.env.OH_PATH = '/test/items';

0 comments on commit 0aa7186

Please sign in to comment.