From f73e966b609a5709d5c6f20e3e4d78cfee466470 Mon Sep 17 00:00:00 2001 From: Ali Tahir Date: Fri, 24 Jan 2020 16:01:18 -0500 Subject: [PATCH] added ability to set configs using environment variables. --- src/api-client.js | 23 ++++++++++++++++++++++- test/getContentList.tests.js | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/api-client.js b/src/api-client.js index 2b9229f..907daa9 100644 --- a/src/api-client.js +++ b/src/api-client.js @@ -25,12 +25,33 @@ const defaultConfig = { } }; +function buildEnvConfig() { + let env = process.env; + let envConfig = {}; + if (env.hasOwnProperty('AGILITY_BASEURL')) { + envConfig.baseUrl = env.AGILITY_BASEURL; + } + if (env.hasOwnProperty('AGILITY_GUID')) { + envConfig.guid = env.AGILITY_GUID; + } + if (env.hasOwnProperty('AGILITY_APIKEY')) { + envConfig.apiKey = env.AGILITY_APIKEY; + } + if (env.hasOwnProperty('AGILITY_ISPREVIEW')){ + envConfig.isPreview = env.AGILITY_ISPREVIEW; + } + + return envConfig; +} + export default function createClient(userConfig) { - + + let envConfig = buildEnvConfig(); //merge our config - user values will override our defaults let config = { ...defaultConfig, + ...envConfig, ...userConfig }; diff --git a/test/getContentList.tests.js b/test/getContentList.tests.js index 4bb7c07..c551ac4 100644 --- a/test/getContentList.tests.js +++ b/test/getContentList.tests.js @@ -300,7 +300,8 @@ describe('getContentList:', function() { api.getContentList({ referenceName: 'posts', languageCode: 'en-us', - filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.EQUAL_TO, value: '40'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}] + filters: [{property: 'properties.versionID', operator: api.types.FilterOperators.GREATER_THAN, value: '40'}, {property: 'properties.referenceName', operator: api.types.FilterOperators.LIKE, value: 'posts'}], + filtersLogicOperator: api.types.FilterLogicOperators.AND }) .then(function(contentList) { assert.strictEqual(contentList.items[0].contentID, 16);