From b12a9a57bd7c1cc0a166142036c31b1eb3b148c9 Mon Sep 17 00:00:00 2001
From: revathi <revathipp@gmail.com>
Date: Tue, 26 Jun 2018 10:54:37 +0530
Subject: [PATCH] Issue #SB-3715 fix: review fixes

---
 src/app.js                                    | 19 ++++++++++++-------
 src/middlewares/filter.middleware.js          |  7 +++----
 src/service/filterService.js                  |  8 ++++----
 src/test/appSpec.js                           |  4 +++-
 src/test/channelFilterRouteSpec.js            |  4 ----
 src/test/metaFilterRouteSpec.js               |  4 ++++
 src/test/middlewares/filterMiddlewareSpec.js  |  9 +++++++++
 src/test/middlewares/requestMiddlewareSpec.js |  7 -------
 src/test/service/filterServiceSpec.js         |  4 ++--
 9 files changed, 37 insertions(+), 29 deletions(-)
 create mode 100644 src/test/metaFilterRouteSpec.js
 create mode 100644 src/test/middlewares/filterMiddlewareSpec.js

diff --git a/src/app.js b/src/app.js
index 831aed4..22785cb 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 2d5fd57..43ca1d3 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 b4061c8..5195d30 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 a94212f..90d57e1 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 b069e4e..064efab 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 0000000..a6bdfc8
--- /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 0000000..5326cb3
--- /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 728ab11..6105f93 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 a0452d0..c69ef0c 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 () {})
 })
-- 
GitLab