diff --git a/src/app.js b/src/app.js index 831aed4681b7116b3fa72a262f48318ff9e7de06..22785cb92de51ea84f3f395c82f84c092c31dc25 100644 --- a/src/app.js +++ b/src/app.js @@ -156,16 +156,21 @@ const telemetryConfig = { telemetry.init(telemetryConfig) -// function to generate the search string - +// function to generate the search filter and return JSON Object function getMetaFilterConfig () { - return setFilterJSONFromEnv() +// Check if the Filter Config service data is defined, if yes, create Object with it + if (filterConfigService !== undefined) { + return getFilterJSONfromConfigService() + } else { + // Call getFilterJSONFromEnv to generate a JSON Object + return getFilterJSONFromEnv() + } } -function setFilterJSONFromEnv () { + +function getFilterJSONFromEnv () { // Generate JSON and return - return setFilterJSON() } -function setFilterJSON () { - +function getFilterJSONfromConfigService () { + // Generate JSON from Config Service and return } diff --git a/src/middlewares/filter.middleware.js b/src/middlewares/filter.middleware.js index 2d5fd571f9b3341ad61ae7491cfec10d1035507a..43ca1d356c0853ff721a4df3e554f9f2d876230b 100644 --- a/src/middlewares/filter.middleware.js +++ b/src/middlewares/filter.middleware.js @@ -3,15 +3,14 @@ var filterService = require('../service/filterService') function addMetaFilters (req, res, next) { // If the request body has filter by metaFilter data, continue with the same filter, do not alter the values - - // else call the getMetaSearchString() function to generate the search string for the meta filters - filterService.getMetaSearchString(function () { + // else call the getMetaSearchData() function to generate the JSON Object for the meta filters + filterService.getMetaSearchData(function () { // Generate JSON and return return setFilterJSON() }) } function setFilterJSON () { - +// Set the new filter Object for filter request body } module.exports.addMetaFilters = addMetaFilters diff --git a/src/service/filterService.js b/src/service/filterService.js index b4061c8f4ac8090cc8320635802cb45951a98339..5195d302617f3a619337839d2c0a67c389cd0e13 100644 --- a/src/service/filterService.js +++ b/src/service/filterService.js @@ -6,9 +6,9 @@ */ var configUtil = require('sb-config-util') -function getMetaSearchString (callback) { - var searchString = configUtil.getConfig('META_FILTER_QUERY_STRING') - callback(null, searchString) +function getMetaSearchData (callback) { + var searchData = configUtil.getConfig('META_FILTER_REQUEST_JSON') + callback(null, searchData) } -module.exports.getMetaSearchString = getMetaSearchString +module.exports.getMetaSearchData = getMetaSearchData diff --git a/src/test/appSpec.js b/src/test/appSpec.js index a94212f5b538eaac359c686fe338ba6dda5ba552..90d57e1d24077d1519e64c90f85e7d9c940db0a8 100644 --- a/src/test/appSpec.js +++ b/src/test/appSpec.js @@ -53,7 +53,9 @@ describe('Check health api', function (done) { it('test for blackList metafilter configured', function () {}) it('test for whitelist metafilter and blackList not configured', function () {}) it('test for whitelist metafilter and blackList is configured', function () {}) - it('check if filter JSON is generated', function () { }) + it('Check if filterConfig service data is available', function () {}) + it('If FilterConfig is null/undefined, generate filter Object from environment variables', function () { }) + it('Check if filter JSON is generated', function () { }) }) // below method used to close server once all the specs are executed diff --git a/src/test/channelFilterRouteSpec.js b/src/test/channelFilterRouteSpec.js index b069e4e5d81e23878fe10a74bb4e4622a9b3ba61..064efaba08e9037bd555ac7ebd286c36b3b8a64a 100644 --- a/src/test/channelFilterRouteSpec.js +++ b/src/test/channelFilterRouteSpec.js @@ -65,7 +65,3 @@ describe('Check for all route to be calling the AddChannelFilter', function () { }) }) }) -describe('Check for all route to be calling the AddMetaFilter', function () { - it('check for filter in config with route', function () {}) - it('check for filter in config with value + route', function () {}) -}) diff --git a/src/test/metaFilterRouteSpec.js b/src/test/metaFilterRouteSpec.js new file mode 100644 index 0000000000000000000000000000000000000000..a6bdfc8ea44fcefecc2b9fc290b80adc05a99518 --- /dev/null +++ b/src/test/metaFilterRouteSpec.js @@ -0,0 +1,4 @@ +describe('Check for all required route to call the AddMetaFilter', function () { + it('check for filter in config with route', function () {}) + it('check for filter in config with value + route', function () {}) +}) diff --git a/src/test/middlewares/filterMiddlewareSpec.js b/src/test/middlewares/filterMiddlewareSpec.js new file mode 100644 index 0000000000000000000000000000000000000000..5326cb3f8c155d36f232ee95f167859c46757aec --- /dev/null +++ b/src/test/middlewares/filterMiddlewareSpec.js @@ -0,0 +1,9 @@ +describe('Initialization of meta filters', function () { + it('check for the request and then do next', function () {}) + it('check for no request and get config', function () {}) + it('check for the filter object property exists in the request body', function () {}) + it('if filter object property is equal to response body property then do not append property to the filter', function () {}) + it('if the filter object property is not equal to response body property then append property to the filter', function () {}) + it('check for getMetaSearchData method creates proper whitelisted search data', function () {}) + it('check for getMetaSearchData method creates proper blacklisted search data', function () {}) +}) diff --git a/src/test/middlewares/requestMiddlewareSpec.js b/src/test/middlewares/requestMiddlewareSpec.js index 728ab11f3c2e0766378e5359a8a8f645c6c55b34..6105f932466d2d2a11e1f028175249e54a902a82 100644 --- a/src/test/middlewares/requestMiddlewareSpec.js +++ b/src/test/middlewares/requestMiddlewareSpec.js @@ -51,10 +51,3 @@ describe('filter of channels', function () { }) }) }) - -describe('Initialization of meta filters', function () { - it('check for the request and then do next', function () {}) - it('check for no request and get config', function () {}) - it('check for getMetaSearchString method creates proper whitelisted search string', function () {}) - it('check for getMetaSearchString method creates proper blacklisted search string', function () {}) -}) diff --git a/src/test/service/filterServiceSpec.js b/src/test/service/filterServiceSpec.js index a0452d033f35344e45a4237212d2018b82a70ca2..c69ef0c30a0dcf5fb43c697edc18f1da878ffe83 100644 --- a/src/test/service/filterServiceSpec.js +++ b/src/test/service/filterServiceSpec.js @@ -21,8 +21,8 @@ describe('filter service', function () { }) }) -describe('content meta filter service', function () { - it('check for getMetaSearchString method', function () {}) +describe('content meta filter service from config', function () { + it('check for getMetaSearchData method', function () {}) it('check for whitelisted metafilter set in config', function () {}) it('check for blacklisted metafilter set in config', function () {}) })