From a8b5f265baf56c963f055a21653c8c6b2b622cb3 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Fri, 21 Jun 2019 19:23:07 +0530 Subject: [PATCH 01/15] added customFunction and tests --- lib/service-personalizer.js | 61 +++++++++++++++++++- package.json | 7 ++- server/boot/service-personalization.js | 32 ++++++++++- test/config.json | 5 +- test/customFunction/index.js | 12 ++++ test/test.js | 79 +++++++++++++++++++++++++- 6 files changed, 186 insertions(+), 10 deletions(-) create mode 100644 test/customFunction/index.js diff --git a/lib/service-personalizer.js b/lib/service-personalizer.js index 3cefc27..108dc44 100755 --- a/lib/service-personalizer.js +++ b/lib/service-personalizer.js @@ -18,6 +18,8 @@ var exprLang = require('oe-expression/lib/expression-language.js'); var mergeQuery = require('loopback-datasource-juggler/lib/utils').mergeQuery; var logger = require('oe-logger'); var log = logger('service-personalizer'); +var customFunction; + /** * This function returns the necessary sorting logic to @@ -130,6 +132,12 @@ var applyPersonalizationRule = function applyPersonalizationRuleFn(ctx, p13nRule }); // arr.push(async.apply(addSort, ctx, p13nRule[instruction])); break; + case 'postCustomFunction': + arr.push({ + type: 'postCustomFunction', + fn: async.apply(executeCustomFunction, ctx, p13nRule[instruction]) + }); + break; case 'union': // unionResults(ctx, p13nRule[instruction]); break; @@ -151,7 +159,7 @@ var applyPersonalizationRule = function applyPersonalizationRuleFn(ctx, p13nRule } } } - return arr.sort(sortFactoryFn()).map(x => x.fn); + return arr.sort(sortFactoryFn()); }; function execute(arr, callback) { @@ -196,6 +204,12 @@ var applyReversePersonalizationRule = function applyReversePersonalizationRuleFn }); // arr.push(async.apply(addReverseFieldValueReplace, ctx, p13nRule[instruction])); break; + case 'preCustomFunction': + arr.push({ + type: 'preCustomFunction', + fn: async.apply(executeCustomFunction, ctx, p13nRule[instruction]) + }); + break; default: } } @@ -441,6 +455,26 @@ function reverseFieldValueReplacementFn(ctx, rule, cb) { } } +//old code +function executeCustomFunctionFn(ctx, customFunctionName) { + // TODO: Security check + var custFn = new Function('ctx', customFunction); + var custFn = function customFnn(ctx, customFunction) { + customFunction(ctx); + }; + + log.debug(ctx.options, 'function - ', customFunction); + custFn(ctx); +} + +//execute custom function +function executeCustomFunction(ctx, instruction, cb) { + let customFunctionName = instruction.functionName; + customFunction[customFunctionName](ctx); + cb(); +} + + /** * Processes a 'filter' instruction. This method checks if underlying datasource to which the model is attached to * supports query based filtering. If yes, it adds a 'where' clause in the query. Otherwise creates a post processing @@ -605,6 +639,27 @@ function addSort(ctx, instruction, cb) { } } +/** + * Custom function + */ +//getCustom function +function loadCustomFunction(fnCache) { + customFunction = fnCache +} + +function getCustomFunction() { + return customFunction; +} + +// +function addCustomFunction(ctx, instruction, cb) { + //instruction has the customFunction Name + // Datasource does not support field name replacement. Add it as a post processing function + addPostProcessingFunction(ctx, 'customFunction', instruction, executeCustomFunctionFn); + cb(); +} + + function createOrderExp(instruction, tempKeys) { if (!Array.isArray(instruction)) { instruction = [instruction]; @@ -797,5 +852,7 @@ module.exports = { getPersonalizationRuleForModel: getPersonalizationRuleForModel, applyPersonalizationRule: applyPersonalizationRule, applyReversePersonalizationRule: applyReversePersonalizationRule, - execute: execute + execute: execute, + loadCustomFunction, + getCustomFunction }; diff --git a/package.json b/package.json index 97165b0..7219bda 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,12 @@ "grunt-mocha-istanbul": "5.0.2", "grunt-mocha-test": "0.13.3", "istanbul": "0.4.5", + "loopback-connector-mongodb": "3.9.2", + "md5": "^2.2.1", "mocha": "5.2.0", + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", "superagent-defaults": "0.1.14", - "supertest": "3.4.2", - "loopback-connector-mongodb": "3.9.2", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master" + "supertest": "3.4.2" }, "repository": { "type": "git", diff --git a/server/boot/service-personalization.js b/server/boot/service-personalization.js index fc46f2b..74b7f43 100644 --- a/server/boot/service-personalization.js +++ b/server/boot/service-personalization.js @@ -24,6 +24,11 @@ var personalizationRuleModel; module.exports = function ServicePersonalization(app, cb) { log.debug(log.defaultContext(), 'In service-personalization.js boot script.'); personalizationRuleModel = app.models.PersonalizationRule; + //requiring customFunction + let servicePersoConfig = app.get('servicePersonalization'); + if ('customFunctionPath' in servicePersoConfig) { + servicePersonalizer.loadCustomFunction(require(servicePersoConfig.customFunctionPath)); + } // Creating 'before save' and 'after save' observer hooks for PersonlizationRule model personalizationRuleModel.observe('before save', personalizationRuleBeforeSave); personalizationRuleModel.observe('after save', personalizationRuleAfterSave); @@ -80,12 +85,27 @@ function personalizationRuleBeforeSave(ctx, next) { // It is good to have if we have a declarative way of validating model existence. var modelName = data.modelName; if (loopback.findModel(modelName, ctx.options)) { - next(); + var nextFlag = true; + if (data.personalizationRule.postCustomFunction) { + if (!(Object.keys(servicePersonalizer.getCustomFunction()).indexOf(data.personalizationRule.postCustomFunction.functionName) > -1) && nextFlag) { + next(new Error('Module \'' + data.personalizationRule.postCustomFunction.functionName + '\' doesn\'t exists.')); + nextFlag = false; + } + } + if (data.personalizationRule.preCustomFunction) { + if (!(Object.keys(servicePersonalizer.getCustomFunction()).indexOf(data.personalizationRule.preCustomFunction.functionName) > -1) && nextFlag) { + next(new Error('Module \'' + data.personalizationRule.precustomFunction.functionName + '\' doesn\'t exists.')); + } + } + if(nextFlag){ + next(); + } } else { // Not sure it is the right way to construct error object to sent in the response. var err = new Error('Model \'' + modelName + '\' doesn\'t exists.'); next(err); } + } /** @@ -257,6 +277,8 @@ function beforeRemoteFindHook(model) { if (rule !== null && typeof rule !== 'undefined') { log.debug(ctx.req.callContext, 'beforeRemoteFindHook personalization rule found , rule: ', rule); var fns = servicePersonalizer.applyPersonalizationRule(ctx, rule.personalizationRule); + fns = fns.filter(x => x.type !== 'postCustomFunction'); + fns = fns.map(x => x.fn); servicePersonalizer.execute(fns, function (err) { if (err) { return next(err); @@ -279,6 +301,8 @@ function beforeRemoteFindOneHook(model) { if (rule !== null && typeof rule !== 'undefined') { log.debug(ctx.req.callContext, 'beforeRemoteFindOneHook personalization rule found , rule: ', rule); var fns = servicePersonalizer.applyPersonalizationRule(ctx, rule.personalizationRule); + fns = fns.filter(x => x.type !== 'postCustomFunction'); + fns = fns.map(x => x.fn); servicePersonalizer.execute(fns, function (err) { if (err) { return next(err); @@ -301,6 +325,8 @@ function beforeRemoteFindByIdHook(model) { if (rule !== null && typeof rule !== 'undefined') { log.debug(ctx.req.callContext, 'beforeRemoteFindByIdHook personalization rule found , rule: ', rule); var fns = servicePersonalizer.applyPersonalizationRule(ctx, rule.personalizationRule); + fns = fns.filter(x => x.type !== 'postCustomFunction'); + fns = fns.map(x => x.fn); servicePersonalizer.execute(fns, function (err) { if (err) { return next(err); @@ -329,9 +355,9 @@ function afterRemotePersonalizationExec(model, ctx, next) { if (rule !== null && typeof rule !== 'undefined') { log.debug(ctx.req.callContext, 'afterRemotePersonalizationExec personalization rule found , rule: ', rule); log.debug(ctx.req.callContext, 'applying PersonalizationRule now'); - log.debug(ctx.req.callContext, 'beforeRemoteFindHook personalization rule found , rule: ', rule); var fns = servicePersonalizer.applyPersonalizationRule(ctx, rule.personalizationRule); + fns = fns.map(x => x.fn); servicePersonalizer.execute(fns, function (err) { if (err) { return next(err); @@ -372,4 +398,4 @@ function beforeRemotePersonalizationExec(model, ctx, next) { next(); } }); -} +} \ No newline at end of file diff --git a/test/config.json b/test/config.json index 40d45f4..ea7fc29 100644 --- a/test/config.json +++ b/test/config.json @@ -19,5 +19,8 @@ "cors": false, "handleErrors": false }, - "legacyExplorer": false + "legacyExplorer": false, + "servicePersonalization" : { + "customFunctionPath": "D:\\Repos\\oecloud.io\\oe-service-personalization_master\\test\\customFunction" + } } diff --git a/test/customFunction/index.js b/test/customFunction/index.js new file mode 100644 index 0000000..5b7a458 --- /dev/null +++ b/test/customFunction/index.js @@ -0,0 +1,12 @@ +var md5 = require('md5'); + +function customFn(ctx) { + ctx.result = ctx.result.map((item) => { + item.name = md5(item.name); + return item; + }); +} + +module.exports = { + customFn +} \ No newline at end of file diff --git a/test/test.js b/test/test.js index ef0137d..9fde77c 100755 --- a/test/test.js +++ b/test/test.js @@ -1574,7 +1574,6 @@ describe(chalk.blue('service personalization test started...'), function () { } var results = resp.body; expect(results.length).to.be.equal(3); - console.log(results); // expect(results[0], 'doesn\'t have the field').to.have.key('billingAddress'); expect('billingAddress' in results[0]).to.be.true; expect(results[0].billingAddress).keys('city', 'state', 'lane'); @@ -1623,6 +1622,84 @@ debugger; }); }); + it('t33 apply customFunction for non-existence model', function (done) { + // Setup personalization rule + var ruleForAndroid = { + 'modelName': 'ProductCatalog123456', + 'personalizationRule': { + 'postCustomFunction': { + 'functionName': 'customFn', + } + }, + 'scope': { + 'device': 'android' + } + }; + + PersonalizationRule.create(ruleForAndroid, function (err, rule) { + if (err) { + return done(); + } else { + return done(new Error('Model doesn\'t exist, but still PersonalizationRule created')); + } + }); + }); + + it('t34 apply customFunction personalizationRule for non-existence function', function (done) { + // Setup personalization rule + var ruleForAndroid = { + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'postCustomFunction': { + 'functionName': 'customFn123', + } + }, + 'scope': { + 'device': 'android' + } + }; + + PersonalizationRule.create(ruleForAndroid, function (err, rule) { + if (err) { + return done(); + } else { + return done(new Error('Function doesn\'t exist, but still PersonalizationRule created')); + } + }); + }); + + it('t35 apply postCustomFunction', function (done) { + // Setup personalization rule + var ruleForAndroid = { + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'postCustomFunction': { + 'functionName': 'customFn', + } + }, + 'scope': { + 'device': 'android' + } + }; + + PersonalizationRule.create(ruleForAndroid, function (err, rule) { + if (err) { + return done(new Error(err)); + } + // var ruleId = rule.id; + api.get(productCatalogUrl) + .set('Accept', 'application/json') + .set('REMOTE_USER', 'testUser') + .set('device', 'android') + .expect(200).end(function (err, resp) { + if (err) { + done(err); + } + done(); + }); + }); + }); + }); }); From 79fe28949ce6a7d99d848cceb6b34fc20555178b Mon Sep 17 00:00:00 2001 From: venkatesh Date: Thu, 27 Jun 2019 19:07:22 +0530 Subject: [PATCH 02/15] updated Runner --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 48dae10..bbd4349 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,7 +49,7 @@ npminstall: - node_modules/ - artifacts/ tags: - - CEP_RUNNER_EE + - CEP_RUNNER mongotest: @@ -73,7 +73,7 @@ mongotest: - artifacts/ when: on_failure tags: - - CEP_RUNNER_EE + - CEP_RUNNER postgrestest: stage: pre-build-test @@ -89,7 +89,7 @@ postgrestest: - time npm install --no-optional - npm run grunt-cover tags: - - CEP_RUNNER_EE + - CEP_RUNNER oracletest: @@ -116,7 +116,7 @@ oracletest: - echo "Oracle user details:"${ORACLE_USERNAME}"/"${ORACLE_PASSWORD} - npm run grunt-cover tags: - - CEP_RUNNER_EE + - CEP_RUNNER pushartifacts: stage: push-artifacts From 5f079b224c110eb2b38e523e8f6ac2c9800b205f Mon Sep 17 00:00:00 2001 From: venkatesh Date: Thu, 27 Jun 2019 19:13:51 +0530 Subject: [PATCH 03/15] fixed eslint issues --- lib/service-personalizer.js | 16 ++++++++-------- server/boot/service-personalization.js | 11 +++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/service-personalizer.js b/lib/service-personalizer.js index 108dc44..bf55e57 100755 --- a/lib/service-personalizer.js +++ b/lib/service-personalizer.js @@ -455,10 +455,10 @@ function reverseFieldValueReplacementFn(ctx, rule, cb) { } } -//old code +// old code function executeCustomFunctionFn(ctx, customFunctionName) { // TODO: Security check - var custFn = new Function('ctx', customFunction); + // var custFn = new Function('ctx', customFunction); var custFn = function customFnn(ctx, customFunction) { customFunction(ctx); }; @@ -467,7 +467,7 @@ function executeCustomFunctionFn(ctx, customFunctionName) { custFn(ctx); } -//execute custom function +// execute custom function function executeCustomFunction(ctx, instruction, cb) { let customFunctionName = instruction.functionName; customFunction[customFunctionName](ctx); @@ -642,23 +642,23 @@ function addSort(ctx, instruction, cb) { /** * Custom function */ -//getCustom function +// getCustom function function loadCustomFunction(fnCache) { - customFunction = fnCache + customFunction = fnCache; } function getCustomFunction() { return customFunction; } -// +/* eslint-disable */ function addCustomFunction(ctx, instruction, cb) { - //instruction has the customFunction Name + // instruction has the customFunction Name // Datasource does not support field name replacement. Add it as a post processing function addPostProcessingFunction(ctx, 'customFunction', instruction, executeCustomFunctionFn); cb(); } - +/* eslint-enable */ function createOrderExp(instruction, tempKeys) { if (!Array.isArray(instruction)) { diff --git a/server/boot/service-personalization.js b/server/boot/service-personalization.js index 74b7f43..bd1eb9e 100644 --- a/server/boot/service-personalization.js +++ b/server/boot/service-personalization.js @@ -24,7 +24,7 @@ var personalizationRuleModel; module.exports = function ServicePersonalization(app, cb) { log.debug(log.defaultContext(), 'In service-personalization.js boot script.'); personalizationRuleModel = app.models.PersonalizationRule; - //requiring customFunction + // requiring customFunction let servicePersoConfig = app.get('servicePersonalization'); if ('customFunctionPath' in servicePersoConfig) { servicePersonalizer.loadCustomFunction(require(servicePersoConfig.customFunctionPath)); @@ -90,14 +90,14 @@ function personalizationRuleBeforeSave(ctx, next) { if (!(Object.keys(servicePersonalizer.getCustomFunction()).indexOf(data.personalizationRule.postCustomFunction.functionName) > -1) && nextFlag) { next(new Error('Module \'' + data.personalizationRule.postCustomFunction.functionName + '\' doesn\'t exists.')); nextFlag = false; - } + } } if (data.personalizationRule.preCustomFunction) { if (!(Object.keys(servicePersonalizer.getCustomFunction()).indexOf(data.personalizationRule.preCustomFunction.functionName) > -1) && nextFlag) { next(new Error('Module \'' + data.personalizationRule.precustomFunction.functionName + '\' doesn\'t exists.')); - } + } } - if(nextFlag){ + if (nextFlag) { next(); } } else { @@ -105,7 +105,6 @@ function personalizationRuleBeforeSave(ctx, next) { var err = new Error('Model \'' + modelName + '\' doesn\'t exists.'); next(err); } - } /** @@ -398,4 +397,4 @@ function beforeRemotePersonalizationExec(model, ctx, next) { next(); } }); -} \ No newline at end of file +} From aebc3ff4b1e10b012c68e6c06f3af6ab8f077a76 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Thu, 27 Jun 2019 19:34:38 +0530 Subject: [PATCH 04/15] Disabling hard check on npm audit --- .gitlab-ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bbd4349..aab5249 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,10 +37,9 @@ npminstall: - echo "Node Modules Installed" - npm config rm registry - mkdir -p ./artifacts/${CI_PROJECT_NAME}/ - - npm audit --json > ./artifacts/${CI_PROJECT_NAME}/vulnerabilities.json - - status_vulnerabilities='echo $?' - - npm audit - - if [ $status_vulnerabilities == 1 ]; then exit_status=1 && echo "Dependency vulnerabilities exist"; fi + - npm audit --json > ./artifacts/${CI_PROJECT_NAME}/vulnerabilities.json || true + - if npm audit; then status_vulnerabilities=0; else status_vulnerabilities=1; fi + - if [ $status_vulnerabilities == 1 ]; then echo "Dependency vulnerabilities exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi artifacts: untracked: true From bc545b46f7ccb49327c07d3aa9f26aa0d7d58c62 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Fri, 28 Jun 2019 12:00:16 +0530 Subject: [PATCH 05/15] added preCustomFunction test --- .gitlab-ci.yml | 3 ++ test/config.js | 3 ++ test/customFunction/index.js | 21 +++++++++---- test/test.js | 57 ++++++++++++++++++++++++++++++++---- 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 test/config.js diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aab5249..40a52a8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -61,6 +61,7 @@ mongotest: - export DB_NAME=${CI_PIPELINE_ID}_mongo - npm config set registry http://10.188.25.62:9002/ - time npm install --no-optional + - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" - npm run grunt-cover - mkdir -p ./artifacts/${CI_PROJECT_NAME}/ - cp -r coverage ./artifacts/${CI_PROJECT_NAME}/ @@ -86,6 +87,7 @@ postgrestest: # - time npm install git+http://evgit/oecloud.io/loopback-connector-postgresql.git --save - npm config set registry http://10.188.25.62:9002/ - time npm install --no-optional + - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" - npm run grunt-cover tags: - CEP_RUNNER @@ -113,6 +115,7 @@ oracletest: - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') - export ORACLE_PASSWORD=$(echo $CI_PROJECT_NAMESPACE | tr '[:upper:]' '[:lower:]') - echo "Oracle user details:"${ORACLE_USERNAME}"/"${ORACLE_PASSWORD} + - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" - npm run grunt-cover tags: - CEP_RUNNER diff --git a/test/config.js b/test/config.js new file mode 100644 index 0000000..6702179 --- /dev/null +++ b/test/config.js @@ -0,0 +1,3 @@ +var config = require('./config.json'); + +config.servicePersonalization.customFunctionPath = process.env.custom_function_path || config.servicePersonalization.customFunctionPath; diff --git a/test/customFunction/index.js b/test/customFunction/index.js index 5b7a458..65de6ba 100644 --- a/test/customFunction/index.js +++ b/test/customFunction/index.js @@ -1,12 +1,23 @@ var md5 = require('md5'); function customFn(ctx) { - ctx.result = ctx.result.map((item) => { - item.name = md5(item.name); - return item; - }); + if(ctx.result && ctx.result.length > 1) { + ctx.result = ctx.result.map((item) => { + item.name = md5(item.name); + return item; + }); + } else if(ctx.res.body) { + ctx.res.body.name = md5(ctx.res.body.name); + } +} + +function hashReqBody(ctx) { + if(ctx.req.body) { + ctx.req.body.name = md5(ctx.req.body.name); + } } module.exports = { - customFn + customFn, + hashReqBody } \ No newline at end of file diff --git a/test/test.js b/test/test.js index 9fde77c..630329b 100755 --- a/test/test.js +++ b/test/test.js @@ -1598,7 +1598,7 @@ describe(chalk.blue('service personalization test started...'), function () { }; PersonalizationRule.create(ruleForAndroid, defContext, function (err, rule) { -debugger; + debugger; if (err) { throw new Error(err); } @@ -1621,7 +1621,9 @@ debugger; }); }); }); + }); + describe('CustomFunction Tests - ', function () { it('t33 apply customFunction for non-existence model', function (done) { // Setup personalization rule var ruleForAndroid = { @@ -1635,7 +1637,7 @@ debugger; 'device': 'android' } }; - + PersonalizationRule.create(ruleForAndroid, function (err, rule) { if (err) { return done(); @@ -1658,7 +1660,7 @@ debugger; 'device': 'android' } }; - + PersonalizationRule.create(ruleForAndroid, function (err, rule) { if (err) { return done(); @@ -1668,7 +1670,7 @@ debugger; }); }); - it('t35 apply postCustomFunction', function (done) { + it('t35 apply postCustomFunction for get request', function (done) { // Setup personalization rule var ruleForAndroid = { 'modelName': 'ProductCatalog', @@ -1681,7 +1683,7 @@ debugger; 'device': 'android' } }; - + PersonalizationRule.create(ruleForAndroid, function (err, rule) { if (err) { return done(new Error(err)); @@ -1700,6 +1702,51 @@ debugger; }); }); + it('t36 apply postCustomFunction for post request', function (done) { + // Setup personalization rule + var ruleForAndroid = { + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'preCustomFunction': { + 'functionName': 'hashReqBody', + } + }, + 'scope': { + 'device': 'android' + } + }; + PersonalizationRule.create(ruleForAndroid, function (err, rule) { + if (err) { + return done(new Error(err)); + } + var postData = { + 'name': 'customOven', + 'desc': 'Customeized oven', + 'category': 'electronics', + 'price': { + 'value': 10000, + 'currency': 'inr' + }, + 'isAvailable': true + }; + + api.post(productCatalogUrl + `?access_token=${accessToken}`) + .set('Accept', 'application/json') + .set('REMOTE_USER', 'testUser') + .set('device', 'android') + .send(postData) + .expect(200).end(function (err, resp) { + if (err) { + done(err); + } else { + var result = JSON.parse(resp.text); + expect(result.name).to.not.equal(postData.name); + done(); + } + }); + }); + }); + }); }); From 25ef7390a0ef1945513785a4b939d7c789e0abe7 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Fri, 28 Jun 2019 12:42:00 +0530 Subject: [PATCH 06/15] added environmentVariable config.js --- server/boot/service-personalization.js | 6 +++++- test/{config.js => config.local.js} | 2 ++ test/customFunction/index.js | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) rename test/{config.js => config.local.js} (87%) diff --git a/server/boot/service-personalization.js b/server/boot/service-personalization.js index bd1eb9e..8e2a7d9 100644 --- a/server/boot/service-personalization.js +++ b/server/boot/service-personalization.js @@ -27,7 +27,11 @@ module.exports = function ServicePersonalization(app, cb) { // requiring customFunction let servicePersoConfig = app.get('servicePersonalization'); if ('customFunctionPath' in servicePersoConfig) { - servicePersonalizer.loadCustomFunction(require(servicePersoConfig.customFunctionPath)); + try { + servicePersonalizer.loadCustomFunction(require(servicePersoConfig.customFunctionPath)); + } catch(e) { + console.error(e); + } } // Creating 'before save' and 'after save' observer hooks for PersonlizationRule model personalizationRuleModel.observe('before save', personalizationRuleBeforeSave); diff --git a/test/config.js b/test/config.local.js similarity index 87% rename from test/config.js rename to test/config.local.js index 6702179..77efd5e 100644 --- a/test/config.js +++ b/test/config.local.js @@ -1,3 +1,5 @@ var config = require('./config.json'); config.servicePersonalization.customFunctionPath = process.env.custom_function_path || config.servicePersonalization.customFunctionPath; + +module.exports = config; diff --git a/test/customFunction/index.js b/test/customFunction/index.js index 65de6ba..db33acb 100644 --- a/test/customFunction/index.js +++ b/test/customFunction/index.js @@ -8,6 +8,8 @@ function customFn(ctx) { }); } else if(ctx.res.body) { ctx.res.body.name = md5(ctx.res.body.name); + } else { + ctx.result.name = md5(ctx.result.name); } } From 6503a707c3093d153c60fb8c362fe54851cd0426 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Fri, 28 Jun 2019 12:56:03 +0530 Subject: [PATCH 07/15] fixed lint issues --- server/boot/service-personalization.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/boot/service-personalization.js b/server/boot/service-personalization.js index 8e2a7d9..c6c4f69 100644 --- a/server/boot/service-personalization.js +++ b/server/boot/service-personalization.js @@ -29,8 +29,8 @@ module.exports = function ServicePersonalization(app, cb) { if ('customFunctionPath' in servicePersoConfig) { try { servicePersonalizer.loadCustomFunction(require(servicePersoConfig.customFunctionPath)); - } catch(e) { - console.error(e); + } catch (e) { + log.error(log.defaultContext(), 'require customFunction', e); } } // Creating 'before save' and 'after save' observer hooks for PersonlizationRule model From d0fc6b8100ca40f3433e94ca9bfccbc47a32fb39 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Tue, 2 Jul 2019 15:55:13 +0530 Subject: [PATCH 08/15] added conditions in config.local.js --- test/config.local.js | 11 ++++++++++- test/customFunction/index.js | 2 -- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/config.local.js b/test/config.local.js index 77efd5e..fa0819e 100644 --- a/test/config.local.js +++ b/test/config.local.js @@ -1,5 +1,14 @@ var config = require('./config.json'); -config.servicePersonalization.customFunctionPath = process.env.custom_function_path || config.servicePersonalization.customFunctionPath; +// add customFunctionPath to config if environment variable is present +if (process.env.custom_function_path && !config.servicePersonalization) { + config.servicePersonalization = new Object({ + customFunctionPath: process.env.custom_function_path + }); +} else if(process.env.custom_function_path && config.servicePersonalization) { + config.servicePersonalization.customFunctionPath = process.env.custom_function_path; +} else { + config.servicePersonalization.customFunctionPath = config.servicePersonalization.customFunctionPath +} module.exports = config; diff --git a/test/customFunction/index.js b/test/customFunction/index.js index db33acb..28a03c8 100644 --- a/test/customFunction/index.js +++ b/test/customFunction/index.js @@ -6,8 +6,6 @@ function customFn(ctx) { item.name = md5(item.name); return item; }); - } else if(ctx.res.body) { - ctx.res.body.name = md5(ctx.res.body.name); } else { ctx.result.name = md5(ctx.result.name); } From cf1944eb8308f23aedcf5fc10a2cf1d4bfc63919 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Thu, 4 Jul 2019 18:36:15 +0530 Subject: [PATCH 09/15] servicePersoConfig issue fixed --- server/boot/service-personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/boot/service-personalization.js b/server/boot/service-personalization.js index c6c4f69..ffd47c2 100644 --- a/server/boot/service-personalization.js +++ b/server/boot/service-personalization.js @@ -26,7 +26,7 @@ module.exports = function ServicePersonalization(app, cb) { personalizationRuleModel = app.models.PersonalizationRule; // requiring customFunction let servicePersoConfig = app.get('servicePersonalization'); - if ('customFunctionPath' in servicePersoConfig) { + if (servicePersoConfig && 'customFunctionPath' in servicePersoConfig) { try { servicePersonalizer.loadCustomFunction(require(servicePersoConfig.customFunctionPath)); } catch (e) { From 7e50c80831e699fcdead7f807e5a476026474e91 Mon Sep 17 00:00:00 2001 From: venkatesh Date: Mon, 8 Jul 2019 11:05:57 +0530 Subject: [PATCH 10/15] fixed lint issues --- test/config.local.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/config.local.js b/test/config.local.js index fa0819e..a38e950 100644 --- a/test/config.local.js +++ b/test/config.local.js @@ -5,7 +5,7 @@ if (process.env.custom_function_path && !config.servicePersonalization) { config.servicePersonalization = new Object({ customFunctionPath: process.env.custom_function_path }); -} else if(process.env.custom_function_path && config.servicePersonalization) { +} else if (process.env.custom_function_path && config.servicePersonalization) { config.servicePersonalization.customFunctionPath = process.env.custom_function_path; } else { config.servicePersonalization.customFunctionPath = config.servicePersonalization.customFunctionPath From cbac13b594dc5de4a1bf5bb80294e055cc50795c Mon Sep 17 00:00:00 2001 From: vamsee Date: Mon, 23 Sep 2019 11:21:06 +0530 Subject: [PATCH 11/15] Using node 10.16.0 in CI --- .gitlab-ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 563aac5..06cc2de 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,17 +4,19 @@ stages: - push-artifacts - performance -image: $REGISTRY/evfoundation-executor-docker13:node8alpine36 variables: DOMAIN_NAME: oecloud.local PERF_DOMAIN_NAME: oecloud.perf REGISTRY: registry.${DOMAIN_NAME} + EXECUTOR_IMAGE: oecloud-executor:10.x + EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:10.x + +image: ${REGISTRY}/${EXECUTOR_IMAGE} before_script: - export project=${CI_PROJECT_NAME//[^[:alnum:]]/} - export group=${CI_PROJECT_NAMESPACE//[^[:alnum:]]/} - export branch=${CI_BUILD_REF_NAME//[^[:alnum:]]/} - - export pipelineId=${CI_PIPELINE_ID//[^[:alnum:]]/} - if [ $branch == "master" ]; then export APP_IMAGE_NAME=$group"-"$project; else export APP_IMAGE_NAME=$group"-"$branch"-"$project; fi - export APP_IMAGE_NAME=$(echo $APP_IMAGE_NAME | tr '[:upper:]' '[:lower:]') - export APP_TAG=latest @@ -92,7 +94,7 @@ postgrestest: oracletest: - image: $REGISTRY/debian-node-oracle-docker + image: ${REGISTRY}/${EXECUTOR_IMAGE_ORACLE} stage: pre-build-test script: - echo 'Performing Oracle Test' From f22c68db24cbf2baad77a0a7689606a97f13ba90 Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 8 Nov 2019 11:05:20 +0530 Subject: [PATCH 12/15] Using node 12.13.0 in CI --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 06cc2de..dbe5be4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,8 +8,8 @@ variables: DOMAIN_NAME: oecloud.local PERF_DOMAIN_NAME: oecloud.perf REGISTRY: registry.${DOMAIN_NAME} - EXECUTOR_IMAGE: oecloud-executor:10.x - EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:10.x + EXECUTOR_IMAGE: oecloud-executor:12.x + EXECUTOR_IMAGE_ORACLE: debian-node-oracle-docker:12.x image: ${REGISTRY}/${EXECUTOR_IMAGE} From 01d2bce6815dd04d9d5ed47d58bc684bfb702fe1 Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 8 Nov 2019 11:46:22 +0530 Subject: [PATCH 13/15] Removing user and password from mongo db config --- test/datasources.mongo.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index 96bc9b7..003f3b5 100644 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -17,15 +17,13 @@ module.exports = "connector": "transient" }, "db": { - "host": mongoHost, - "port": 27017, - "url": "mongodb://" + mongoHost + ":27017/" + dbName, - "database": dbName, - "password": "admin", - "name": "db", - "connector": "mongodb", - "user": "admin", - "connectionTimeout": 500000 + 'host': mongoHost, + 'port': 27017, + 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'database': dbName, + 'name': 'db', + 'connector': 'mongodb', + 'connectionTimeout': 500000 } }; From 958d88909fb4f3f11c4dcf096510d6340dc67dab Mon Sep 17 00:00:00 2001 From: vamsee Date: Fri, 10 Jan 2020 16:52:14 +0530 Subject: [PATCH 14/15] removed unneeded packages and updated ci --- .eslintignore | 13 +-- .eslintrc | 2 +- .gitignore | 1 + .gitlab-ci.yml | 128 +++++++++++++------------ Gruntfile.js | 7 +- package.json | 9 +- test/config.local.js | 10 +- test/customFunction/index.js | 28 +++--- test/datasources.json | 2 +- test/datasources.mongo.js | 24 ++--- test/datasources.oracle.js | 10 +- test/datasources.postgres.js | 39 ++++---- test/oracle-utility.js | 176 +++++++++++++++++++---------------- test/test.js | 164 +++++++++++++------------------- 14 files changed, 294 insertions(+), 319 deletions(-) diff --git a/.eslintignore b/.eslintignore index 398a1eb..9c8d714 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ -/client/ -/coverage/ -/node_modules/ -server/dropdb.js -/lib/expression-language/expression-syntax-parser.js -/test/ +build/ +client/ +coverage/ +node_modules/ +test/ +drop.js +Gruntfile.js diff --git a/.eslintrc b/.eslintrc index 8f2f7cc..6edc78f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -111,7 +111,7 @@ "no-undefined": 1, // http://eslint.org/docs/rules/no-undefined "no-with": 2, // http://eslint.org/docs/rules/no-with "handle-callback-err": 1, // http://eslint.org/docs/rules/handle-callback-err - "radix": 2, // http://eslint.org/docs/rules/radix + "radix": 0, // http://eslint.org/docs/rules/radix "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife "yoda": 2, // http://eslint.org/docs/rules/yoda diff --git a/.gitignore b/.gitignore index ef8335e..e9bfceb 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ out/ *.zip /common/models/test package-lock.json +oracle-user.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dbe5be4..540f2bd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,29 +17,31 @@ before_script: - export project=${CI_PROJECT_NAME//[^[:alnum:]]/} - export group=${CI_PROJECT_NAMESPACE//[^[:alnum:]]/} - export branch=${CI_BUILD_REF_NAME//[^[:alnum:]]/} - - if [ $branch == "master" ]; then export APP_IMAGE_NAME=$group"-"$project; else export APP_IMAGE_NAME=$group"-"$branch"-"$project; fi + - if [ ${group} == "oecloudio" ]; then export APP_IMAGE_NAME=$project; else export APP_IMAGE_NAME=$group"-"$project; fi - export APP_IMAGE_NAME=$(echo $APP_IMAGE_NAME | tr '[:upper:]' '[:lower:]') - - export APP_TAG=latest + - if [ ${branch} == "master" ]; then export APP_TAG=latest; else export APP_TAG=${branch}; fi + - export APP_TAG=$(echo $APP_TAG | tr '[:upper:]' '[:lower:]') + + - npm config set unsafe-perm true + - npm config set progress false + - npm config set registry ${NPM_REGISTRY} + # - npm config set registry https://registry.npmjs.org/ npminstall: stage: pre-build script: - echo "Performing code style check..." - - status_eslint=0 - - exit_status=0 - - npm set progress=false - - npm config set registry ${NPM_REGISTRY} - # - npm config set registry http://registry.npmjs.org/ + - export status_eslint=0 + - export exit_status=0 - time npm install eslint babel-eslint --no-optional - if npm run lint; then status_eslint=0; else status_eslint=1; fi - - if [ $status_eslint == 1 ]; then exit_status=1 && echo "esLint errors exist"; fi + - if [ $status_eslint == 1 ]; then export exit_status=1 && echo "esLint errors exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi - echo "Code style check done successfully" - time npm install --no-optional - echo "Node Modules Installed" - npm config rm registry - - mkdir -p ./artifacts/${CI_PROJECT_NAME}/ - - npm audit --json > ./artifacts/${CI_PROJECT_NAME}/vulnerabilities.json || true + - npm audit --json > vulnerabilities.json || true - if npm audit; then status_vulnerabilities=0; else status_vulnerabilities=1; fi - if [ $status_vulnerabilities == 1 ]; then echo "Dependency vulnerabilities exist"; fi - if [ $exit_status == 1 ]; then exit $exit_status; fi @@ -47,75 +49,76 @@ npminstall: expire_in: 2h paths: - node_modules/ - - artifacts/ + - vulnerabilities.json tags: - CEP_RUNNER - mongotest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ stage: pre-build-test + variables: + NODE_ENV: mongo + DB: mongo + MONGO_HOST: 10.73.53.144 + MONGO_PORT: '27017' + DB_NAME: ${CI_JOB_ID}_mongo script: - echo 'Performing MongoDB Test' - - export NODE_ENV=mongo - - export MONGO_HOST="10.73.53.144" - - export DB=mongo - - export DB_NAME=${CI_JOB_ID}_mongo - - npm config set registry ${NPM_REGISTRY} - - time npm install --no-optional - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" + - time npm install --no-optional - npm run grunt-cover - - mkdir -p ./artifacts/${CI_PROJECT_NAME}/ - - cp -r coverage ./artifacts/${CI_PROJECT_NAME}/ artifacts: expire_in: 2h paths: - coverage/ - - artifacts/ - when: on_failure tags: - CEP_RUNNER postgrestest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ stage: pre-build-test + variables: + NODE_ENV: postgres + DB: postgres + POSTGRES_HOST: 10.73.53.144 + POSTGRES_PORT: '5432' + DB_NAME: ${CI_JOB_ID}_pg + ENABLE_DS_AUTOUPDATE: 'true' script: - echo 'Performing PostgreSQL Test' - - export NODE_ENV=postgres - - export DB=postgres - - export POSTGRES_HOST="10.73.53.144" - - export DB_NAME=${CI_JOB_ID}_pg - - export ENABLE_DS_AUTOUPDATE=true - # - time npm install git+http://evgit/oecloud.io/loopback-connector-postgresql.git --save - - npm config set registry ${NPM_REGISTRY} - - time npm install --no-optional - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" + - time npm install --no-optional - npm run grunt-cover tags: - - CEP_RUNNER - + - CEP_RUNNER oracletest: + coverage: /Statements.*?(\d+(?:\.\d+)?)%/ image: ${REGISTRY}/${EXECUTOR_IMAGE_ORACLE} stage: pre-build-test + variables: + NODE_ENV: oracle + DB: oracle + ORACLE_HOST: 10.73.53.144 + ORACLE_PORT: '1521' + ORACLE_SYSUSER: oeadmin + ORACLE_SYSPASSWORD: oeadmin + ORACLE_SID: ORCLCDB + ENABLE_DS_AUTOUPDATE: 'true' script: - echo 'Performing Oracle Test' - - export APP_TAG=oracle - - export NODE_ENV=oracle - - export ORACLE_HOST=10.73.53.144 - - export ORACLE_SYSUSER=oeadmin - - export ORACLE_SYSPASSWORD=oeadmin - - export ORACLE_SID=ORCLCDB - - export DB_NAME=${CI_JOB_ID}_pg - - npm config set registry ${NPM_REGISTRY} - - time npm install git+http://evgit/oecloud.io/oe-connector-oracle.git --no-optional + # - export DB_NAME=${CI_JOB_ID}_pg + # - time npm install git+http://evgit/oecloud.io/oe-connector-oracle.git#master --no-optional + - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" - time npm install --no-optional - mv /oracledb node_modules/ - - export CI_PROJECT_NAMESPACE=${group} - node test/oracle-utility.js - - export ORACLE_USERNAME=${CI_PROJECT_NAMESPACE}"-"${CI_PROJECT_NAME} - - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') - - export ORACLE_PASSWORD=$(echo $CI_PROJECT_NAMESPACE | tr '[:upper:]' '[:lower:]') + # - export ORACLE_USERNAME=${group}"_"${project} + # - export ORACLE_USERNAME=$(echo $ORACLE_USERNAME | tr '[:lower:]' '[:upper:]') + # - export ORACLE_PASSWORD=$(echo $group | tr '[:upper:]' '[:lower:]') + - . ./oracle-user.sh + - env | grep -i oracle - echo "Oracle user details:"${ORACLE_USERNAME}"/"${ORACLE_PASSWORD} - - export custom_function_path="${CI_PROJECT_DIR}/test/customFunction" - npm run grunt-cover tags: - CEP_RUNNER @@ -124,10 +127,15 @@ pushartifacts: stage: push-artifacts script: - echo "Copying all artifacts" + - mkdir -p ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - cp vulnerabilities.json ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ + - cp -r coverage/ ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/ - git clone http://10.73.97.24/oecloud.io/build-tools.git - sh ./build-tools/push_artifacts.sh tags: - CEP_RUNNER + only: + - /^.*/@oecloud.io/oe-service-personalization performancejob: image: $REGISTRY/jmeter:docker @@ -135,38 +143,38 @@ performancejob: variables: NODE_ENV: "mongo" MONGO_HOST: "10.73.97.17" + MONGO_PORT: "27017" DB_NAME: "${CI_JOB_ID}_mongo" APP_PROTOCOL: "https" APP_PORT: "443" PERF_USERS: "1" PERF_LOOPCOUNT: "50000" script: - - npm set progress=false - - npm config set registry ${NPM_REGISTRY} - #- npm config set registry https://registry.npmjs.org/ - - if docker stack rm ${APP_IMAGE_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi + - export STACK_NAME=${APP_IMAGE_NAME}-${APP_TAG} + - export APP_URL=${APP_IMAGE_NAME}-${APP_TAG}.${PERF_DOMAIN_NAME} + - if [ ${branch} == "master" ]; then export STACK_NAME=${APP_IMAGE_NAME}; export APP_URL=${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}; fi + - if docker stack rm ${STACK_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi - time npm install --no-optional - - export APP_URL=${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME} - git clone http://10.73.97.24/oecloud.io/build-tools.git - sed 's/\$REGISTRY/'"$REGISTRY"'/g' ./build-tools/performance/Dockerfile > Dockerfile - - echo "Building ${APP_IMAGE_NAME} image and pushing to registry..." + - echo "Building ${APP_IMAGE_NAME}:${APP_TAG} image and pushing to registry..." - time docker image build -t ${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG} --no-cache --pull . - time docker image push ${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG} - echo "Image (${REGISTRY}/${APP_IMAGE_NAME}:${APP_TAG}) built and pushed to registry" - - docker stack deploy --compose-file ./build-tools/performance/docker-compose.yml ${APP_IMAGE_NAME} + - docker stack deploy --compose-file ./build-tools/performance/docker-compose.yml ${STACK_NAME} - export HTTP_RESPONSE_CODE=200 - export countElapsed=0 - export app_exit_status=0 - - export no_proxy=$no_proxy,${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME} + - export no_proxy=$no_proxy,${APP_URL} - export NO_PROXY=$no_proxy - - echo "${DOCKER_ROUTER_HOST} ${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}" >> /etc/hosts - - export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}/explorer/) - - while [ ${isStarted} -ne ${HTTP_RESPONSE_CODE} ]; do let countElapsed=countElapsed+1; echo ""; sleep 10; export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}/explorer/); echo -n "Waiting till the URL is up..."; echo ${isStarted}; if [ $countElapsed -eq 18 ] ; then export app_exit_status=1; export isStarted=${HTTP_RESPONSE_CODE}; fi; done - - if [ $app_exit_status -eq 1 ]; then echo "App failed to start....."; docker stack ps ${APP_IMAGE_NAME}; docker service logs ${APP_IMAGE_NAME}_web; docker stack rm ${APP_IMAGE_NAME}; exit $app_exit_status; else echo "Your application URL is accessible @ https://${APP_IMAGE_NAME}.${PERF_DOMAIN_NAME}/"; fi - - mkdir -p ./artifacts/${CI_PROJECT_NAME}/performance + - echo "${DOCKER_ROUTER_HOST} ${APP_URL}" >> /etc/hosts + - export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_URL}/api/ModelDefinitions) + - while [ ${isStarted} -ne ${HTTP_RESPONSE_CODE} ]; do let countElapsed=countElapsed+1; echo ""; sleep 10; export isStarted=$(curl -k --write-out %{http_code} --output curl.out --silent https://${APP_URL}/api/ModelDefinitions); echo -n "Waiting till the URL is up..."; echo ${isStarted}; if [ $countElapsed -eq 18 ] ; then export app_exit_status=1; export isStarted=${HTTP_RESPONSE_CODE}; fi; done + - if [ $app_exit_status -eq 1 ]; then echo "App failed to start....."; docker stack ps ${STACK_NAME}; docker service logs ${STACK_NAME}_web; docker stack rm ${STACK_NAME}; exit $app_exit_status; else echo "Your application URL is accessible @ https://${APP_URL}/"; fi + - mkdir -p ./artifacts/${CI_PROJECT_NAME}/${CI_BUILD_REF_NAME}/performance - sh ./build-tools/performance/performance.sh - sh ./build-tools/push_artifacts.sh - - if docker stack rm ${APP_IMAGE_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi + - if docker stack rm ${STACK_NAME}; then echo "stack removed"; else echo "nothing found in stack"; fi when: manual tags: - PERF_RUNNER diff --git a/Gruntfile.js b/Gruntfile.js index 7e76da0..a3c05b2 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -9,6 +9,7 @@ module.exports = function GruntConfig(grunt) { // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), + clean: { coverage: { src: ['coverage/'] @@ -39,12 +40,8 @@ module.exports = function GruntConfig(grunt) { }); // Add the grunt-mocha-test tasks. - grunt.loadNpmTasks('grunt-mocha-test'); - grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.loadNpmTasks('grunt-contrib-clean'); - - grunt.loadNpmTasks('grunt-mkdir'); - grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.registerTask('test-with-coverage', ['clean:coverage', 'mocha_istanbul']); }; diff --git a/package.json b/package.json index 4bc0765..ef2d4fd 100644 --- a/package.json +++ b/package.json @@ -24,23 +24,18 @@ "devDependencies": { "babel-eslint": "7.2.3", "chai": "3.4.1", - "chai-datetime": "1.4.0", "chai-things": "0.2.0", "chalk": "1.1.1", "eslint": "4.10.0", "grunt": "1.0.4", - "grunt-banner": "0.6.0", "grunt-cli": "1.3.2", "grunt-contrib-clean": "2.0.0", - "grunt-contrib-copy": "1.0.0", - "grunt-jsbeautifier": "0.2.13", - "grunt-mkdir": "1.0.0", "grunt-mocha-istanbul": "5.0.2", - "grunt-mocha-test": "0.13.3", "istanbul": "0.4.5", - "loopback-connector-mongodb": "3.9.2", "md5": "^2.2.1", "mocha": "5.2.0", + "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#master", + "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", "superagent-defaults": "0.1.14", "supertest": "3.4.2" diff --git a/test/config.local.js b/test/config.local.js index a38e950..5b11113 100644 --- a/test/config.local.js +++ b/test/config.local.js @@ -2,13 +2,13 @@ var config = require('./config.json'); // add customFunctionPath to config if environment variable is present if (process.env.custom_function_path && !config.servicePersonalization) { - config.servicePersonalization = new Object({ - customFunctionPath: process.env.custom_function_path - }); + config.servicePersonalization = new Object({ + customFunctionPath: process.env.custom_function_path + }); } else if (process.env.custom_function_path && config.servicePersonalization) { - config.servicePersonalization.customFunctionPath = process.env.custom_function_path; + config.servicePersonalization.customFunctionPath = process.env.custom_function_path; } else { - config.servicePersonalization.customFunctionPath = config.servicePersonalization.customFunctionPath + config.servicePersonalization.customFunctionPath = config.servicePersonalization.customFunctionPath; } module.exports = config; diff --git a/test/customFunction/index.js b/test/customFunction/index.js index 28a03c8..b0207a2 100644 --- a/test/customFunction/index.js +++ b/test/customFunction/index.js @@ -1,23 +1,23 @@ var md5 = require('md5'); function customFn(ctx) { - if(ctx.result && ctx.result.length > 1) { - ctx.result = ctx.result.map((item) => { - item.name = md5(item.name); - return item; - }); - } else { - ctx.result.name = md5(ctx.result.name); - } + if (ctx.result && ctx.result.length > 1) { + ctx.result = ctx.result.map((item) => { + item.name = md5(item.name); + return item; + }); + } else { + ctx.result.name = md5(ctx.result.name); + } } function hashReqBody(ctx) { - if(ctx.req.body) { - ctx.req.body.name = md5(ctx.req.body.name); - } + if (ctx.req.body) { + ctx.req.body.name = md5(ctx.req.body.name); + } } module.exports = { - customFn, - hashReqBody -} \ No newline at end of file + customFn, + hashReqBody +}; diff --git a/test/datasources.json b/test/datasources.json index 64f53fe..bf55e6b 100644 --- a/test/datasources.json +++ b/test/datasources.json @@ -14,7 +14,7 @@ "database": "oe-service-personalization-test", "password": "admin", "name": "db", - "connector": "mongodb", + "connector": "oe-connector-mongodb", "user": "admin", "connectionTimeout": 500000 } diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index 003f3b5..c774b4f 100644 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -5,24 +5,24 @@ * */ var mongoHost = process.env.MONGO_HOST || 'localhost'; +var mongoPort = process.env.MONGO_PORT ? parseInt(process.env.MONGO_PORT) : 27017; var dbName = process.env.DB_NAME || 'oe-service-personalization-test'; -module.exports = -{ - "memdb": { - "name": "memdb", - "connector": "memory" +module.exports = { + 'memdb': { + 'name': 'memdb', + 'connector': 'memory' }, - "transient": { - "name": "transient", - "connector": "transient" + 'transient': { + 'name': 'transient', + 'connector': 'transient' }, - "db": { + 'db': { 'host': mongoHost, - 'port': 27017, - 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'port': mongoPort, + 'url': 'mongodb://' + mongoHost + ':' + mongoPort + '/' + dbName, 'database': dbName, 'name': 'db', - 'connector': 'mongodb', + 'connector': 'oe-connector-mongodb', 'connectionTimeout': 500000 } }; diff --git a/test/datasources.oracle.js b/test/datasources.oracle.js index 8792ffd..a5db290 100644 --- a/test/datasources.oracle.js +++ b/test/datasources.oracle.js @@ -4,16 +4,10 @@ * Bangalore, India. All Rights Reserved. * */ -/** - ** - ** ©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary), - ** Bangalore, India. All Rights Reserved. - ** - **/ -var oracleSID = process.env.ORACLE_SID || 'orclpdb.ad.infosys.com'; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; var oracleUserName = process.env.ORACLE_USERNAME || 'oeadmin'; var oracleUserPassword = process.env.ORACLE_PASSWORD || 'oeadmin'; diff --git a/test/datasources.postgres.js b/test/datasources.postgres.js index adaaa76..7cb4916 100644 --- a/test/datasources.postgres.js +++ b/test/datasources.postgres.js @@ -5,29 +5,28 @@ * */ var postgresHost = process.env.POSTGRES_HOST || 'localhost'; +var postgresPort = process.env.POSTGRES_PORT ? parseInt(process.env.POSTGRES_PORT) : 5432; var dbName = process.env.DB_NAME || 'oe-service-personalization-test'; -module.exports = -{ - "memdb": { - "name": "memdb", - "connector": "memory" +module.exports = { + 'memdb': { + 'name': 'memdb', + 'connector': 'memory' }, - "transient": { - "name": "transient", - "connector": "transient" + 'transient': { + 'name': 'transient', + 'connector': 'transient' }, - - "db": { - "host": postgresHost, - "port": 5432, - "url": "postgres://postgres:postgres@" + postgresHost + ":5432/" + dbName, - "database": dbName, - "password": "postgres", - "name": "db", - "connector": "oe-connector-postgresql", - "user": "postgres", - "max": 50, - "connectionTimeout": 50000 + 'db': { + 'host': postgresHost, + 'port': postgresPort, + 'url': 'postgres://postgres:postgres@' + postgresHost + ':' + postgresPort + '/' + dbName, + 'database': dbName, + 'password': 'postgres', + 'name': 'db', + 'connector': 'oe-connector-postgresql', + 'user': 'postgres', + 'max': 50, + 'connectionTimeout': 50000 } }; diff --git a/test/oracle-utility.js b/test/oracle-utility.js index 153da7f..40a1734 100644 --- a/test/oracle-utility.js +++ b/test/oracle-utility.js @@ -15,22 +15,29 @@ // ORACLE_SYSUSER // ORACLE_SYSPASSWORD // ORACLE_SID -// CI_PROJECT_NAME // CI_PROJECT_NAMESPACE +// CI_PROJECT_NAME var oracledb = require('oracledb'); var async = require('async'); +var fs = require('fs'); +var os = require('os'); + var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleConnectSettings = { 'password': process.env.ORACLE_SYSPASSWORD || 'manager1', 'user': process.env.ORACLE_SYSUSER || 'sys', - 'connectString': oracleHost + ':' + oraclePort + '/' + (process.env.ORACLE_SID || 'orclpdb.ad.infosys.com') + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID }; -var userName = process.env.CI_PROJECT_NAMESPACE.toUpperCase() + '-' + (process.env.CI_PROJECT_NAME || 'oecloud').toUpperCase(); -var password = process.env.CI_PROJECT_NAMESPACE.toLowerCase(); +var namespace = process.env.CI_PROJECT_NAMESPACE ? process.env.CI_PROJECT_NAMESPACE.replace(/[^a-zA-Z0-9]/g, '') : 'oecloudio'; +var name = process.env.CI_PROJECT_NAME ? process.env.CI_PROJECT_NAME.replace(/[^a-zA-Z0-9]/g, '') : 'oecloud'; + +var userName = namespace.toUpperCase() + '_' + name.toUpperCase(); +var password = namespace.toLowerCase(); var grants = [ 'CREATE VIEW', @@ -44,30 +51,32 @@ var grants = [ ]; function createUser(connection, cb) { - var sql = 'alter session set "_ORACLE_SCRIPT"=true'; - connection.execute(sql, function (e, r) { - if (e) { - console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + e); + var alterSQL = 'alter session set "_ORACLE_SCRIPT"=true'; + connection.execute(alterSQL, function (alterErr, alterRes) { + if (alterErr) { + console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + alterErr); } - console.log(sql, ' ......... ok'); - var sql = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + console.log(alterSQL, ' ......... ok'); - connection.execute(sql, function (err, result) { - if (err) { - throw new Error('Unable to create user ' + userName + ' Error :' + err); + var createUserSQL = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + connection.execute(createUserSQL, function (createErr, createRes) { + if (createErr) { + console.error(createErr); + throw new Error('Unable to create user ' + userName); } - console.log(sql, ' ......... ok'); - async.each(grants, function (g, callback) { - var sql = 'GRANT ' + g + ' to "' + userName + '"'; + console.log(createUserSQL, ' ......... ok'); - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute grant ' + sql); + async.each(grants, function (g, callback) { + var grantSQL = 'GRANT ' + g + ' to "' + userName + '"'; + connection.execute(grantSQL, function (grantErr, grantRes) { + if (grantErr) { + console.error(grantErr); + throw new Error('Unable to execute grant ' + grantSQL); } - console.log(sql, ' ......... ok'); + console.log(grantSQL, ' ......... ok'); return callback(); }); - }, function (err) { + }, function (grantAsyncErr) { console.log('User ' + userName + ' Created successfully'); return cb(); }); @@ -75,78 +84,83 @@ function createUser(connection, cb) { }); } - function dropTables(cb) { - var oracleConnectSettings2 = Object.assign({}, oracleConnectSettings); - oracleConnectSettings2.user = userName; - oracleConnectSettings2.password = password; - - oracledb.getConnection( - oracleConnectSettings2, - function (err, connection) { - if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + var oracleUserConnectSettings = { + 'password': password, + 'user': userName, + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID + }; + + oracledb.getConnection(oracleUserConnectSettings, function (userConnectionErr, connection) { + if (userConnectionErr) { + console.error(userConnectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleUserConnectSettings)); + } + + var totalRows = 1000; + var selectDropTableSQL = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; + connection.execute(selectDropTableSQL, {}, { maxRows: totalRows }, function (selectDropErr, selectDropRes) { + if (selectDropErr) { + console.error(selectDropErr); + throw new Error('Unable to find tables ' + userName); } - var sql = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; - var totalRows = 1000; - connection.execute(sql, {}, {maxRows: totalRows}, function (err, result) { - if (err) { - throw new Error('Unable to find tables ' + userName + ' Error :' + err); - } - connection.execute(sql, {}, {maxRows: totalRows}, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute droping of table ' + sql); - } - if (!result2 || !result2.rows || result2.rows.length === 0) { - return cb(); + if (!selectDropRes || !selectDropRes.rows || selectDropRes.rows.length === 0) { + return cb(); + } + + async.each(selectDropRes.rows, function (row, callback) { + var dropTableSQL = row[0]; + connection.execute(dropTableSQL, function (dropTableErr, dropTableRes) { + if (dropTableErr) { + console.error(dropTableErr); + throw new Error('Unable to drop table\nSQL: ' + sql); } - async.each(result2.rows, function (row, callback) { - var sql = row[0]; - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to drop table\nERROR : ' + err2 + '\nSQL : ' + sql); - } - console.log(sql, ' ......... ok'); - return callback(); - }); - }, function (err) { - console.log('Tables of user ' + userName + ' dropped successfully'); - return cb(); - }); + console.log(dropTableSQL, ' ......... ok'); + return callback(); }); + }, function (dropAsyncErr) { + console.log('Tables of user ' + userName + ' dropped successfully'); + return cb(); }); }); + }); } -oracledb.getConnection( - oracleConnectSettings, - function (err, connection) { +function generateUserBundle() { + console.log("Generating oracle user details shell script"); + fs.writeFileSync('./oracle-user.sh', '#!/bin/sh' + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_USERNAME=' + userName + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_PASSWORD=' + password + os.EOL); +} + +oracledb.getConnection(oracleConnectSettings, function (connectionErr, connection) { + if (connectionErr) { + console.error(connectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + } + var sql = "select username, user_id from dba_users where username = '" + userName + "'"; + console.log(sql); + connection.execute(sql, function (err, result) { if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + console.error(err); return; } - var sql = "select username, user_id from dba_users where username = '" + userName + "'"; - console.log(sql); - connection.execute(sql, - function (err, result) { + if (!result.rows || result.rows.length == 0) { + createUser(connection, function (err) { if (err) { - console.error(err); return; + return process.exit(1); } - if (!result.rows || result.rows.length == 0) { - createUser(connection, function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); - } else { - dropTables(function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); + generateUserBundle(); + return process.exit(); + }); + } else { + dropTables(function (err) { + if (err) { + return process.exit(1); } + generateUserBundle(); + return process.exit(); }); + } }); - +}); diff --git a/test/test.js b/test/test.js index 630329b..b75fa92 100755 --- a/test/test.js +++ b/test/test.js @@ -53,10 +53,9 @@ describe(chalk.blue('service personalization test started...'), function () { // log.error(err); return done(err); - } else { - // accessToken = res.body.id; - return done(); } + // accessToken = res.body.id; + return done(); }); }); @@ -73,10 +72,9 @@ describe(chalk.blue('service personalization test started...'), function () { if (err) { // log.error(err); return done(err); - } else { - accessToken = res.body.id; - return done(); } + accessToken = res.body.id; + return done(); }); }); PersonalizationRule = loopback.findModel('PersonalizationRule'); @@ -91,7 +89,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'currency': 'inr' }, 'isAvailable': true, - "productOwnerId": 1 + 'productOwnerId': 1 }; var item2 = { 'name': 'office chair', @@ -561,7 +559,7 @@ describe(chalk.blue('service personalization test started...'), function () { }); }); // the below won't work in postgres or oracle. Since - // JSON objects are not represented correctly for the + // JSON objects are not represented correctly for the // necessary operation to happen correctly. Hence the // exclusion. xit('t12 sort: should handle nested sorting', function (done) { @@ -580,7 +578,6 @@ describe(chalk.blue('service personalization test started...'), function () { PersonalizationRule.create(ruleForAndroid, {}, function (err, rule) { - if (err) { throw new Error(err); } @@ -598,7 +595,6 @@ describe(chalk.blue('service personalization test started...'), function () { expect(results[0].name).to.be.equal('office chair'); expect(results[0].price.value).to.be.equal(5000); done(); - }); }); }); @@ -691,11 +687,10 @@ describe(chalk.blue('service personalization test started...'), function () { }; PersonalizationRule.create(ruleForAndroid, {}, function (err, rule) { - if (err) { throw new Error(err); } - //var ruleId = rule.id; + // var ruleId = rule.id; var postData = { 'product name': 'o1ven', @@ -723,7 +718,6 @@ describe(chalk.blue('service personalization test started...'), function () { done(); } }); - }); }); @@ -745,11 +739,10 @@ describe(chalk.blue('service personalization test started...'), function () { }; PersonalizationRule.create(ruleForAndroid, {}, function (err, rule) { - if (err) { throw new Error(err); } - //var ruleId = rule.id; + // var ruleId = rule.id; var postData = { 'name': 'new oven', @@ -776,12 +769,10 @@ describe(chalk.blue('service personalization test started...'), function () { done(); } }); - }); }); - it('t17 should replace field names and field value names when scope of personalization rule matches', function (done) { // Setup personalization rule var ruleForAndroid = { @@ -814,7 +805,7 @@ describe(chalk.blue('service personalization test started...'), function () { // 'name': { // 'oven': 'new_oven_ios' // } - // } + // } // }, // 'scope': { // 'device': 'ios' @@ -842,7 +833,6 @@ describe(chalk.blue('service personalization test started...'), function () { var personalizationRuleArray = [ruleForAndroid, ruleForIos]; PersonalizationRule.create(personalizationRuleArray, {}, function (err, rules) { - if (err) { throw new Error(err); } @@ -891,13 +881,10 @@ describe(chalk.blue('service personalization test started...'), function () { done(); }); }); - - - }); }); - //Nested input values + // Nested input values it('t18 (Nested input) should replace field names and field value names when scope of personalization rule matches while posting', function (done) { // Setup personalization rule var ruleForAndroid = { @@ -926,7 +913,6 @@ describe(chalk.blue('service personalization test started...'), function () { var personalizationRule = ruleForAndroid; PersonalizationRule.create(personalizationRule, {}, function (err, rules) { - var postData = { 'name': 'oven', 'desc': 'oven', @@ -993,7 +979,6 @@ describe(chalk.blue('service personalization test started...'), function () { var personalizationRule = ruleForAndroid; PersonalizationRule.create(personalizationRule, {}, function (err, rules) { - if (err) { throw new Error(err); } @@ -1007,16 +992,14 @@ describe(chalk.blue('service personalization test started...'), function () { var result = results.filter(function (obj) { if (obj.id === '9898') { return true; - } else { - return false; } + return false; }); expect(result[0].price).keys('price_currency', 'value'); expect(result[0]).to.include.keys('product_name_android', 'product_description_android'); expect(result[0].product_name_android).to.be.equal('new_oven_android'); expect(result[0].price.price_currency).to.be.equal('IndianRupee'); done(); - }); }); }); @@ -1049,7 +1032,6 @@ describe(chalk.blue('service personalization test started...'), function () { var personalizationRule = ruleForAndroid; PersonalizationRule.create(personalizationRule, {}, function (err, rules) { - if (err) { throw new Error(err); } @@ -1063,16 +1045,14 @@ describe(chalk.blue('service personalization test started...'), function () { var result = results.filter(function (obj) { if (obj.id === '9898') { return true; - } else { - return false; } + return false; }); expect(result[0].price).keys('currency', 'value'); expect(result[0]).to.include.keys('category', 'price', 'isAvailable', 'id', 'name', 'desc'); expect(result[0].name).to.be.equal('oven'); expect(result[0].price.currency).to.be.equal('inr'); done(); - }); }); }); @@ -1110,10 +1090,8 @@ describe(chalk.blue('service personalization test started...'), function () { expect(results[0]).to.include.keys('ProductCatalog'); expect(results[0].ProductCatalog).to.have.length(1); done(); - }); }); - }); it('t22 should replace field value names array datatype while posting when fieldValueReplace personalization is configured', function (done) { @@ -1124,7 +1102,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'fieldValueReplace': { 'keywords': { 'Alpha': 'A', - "Bravo": 'B' + 'Bravo': 'B' } } }, @@ -1145,7 +1123,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'value': 5000, 'currency': 'inr' }, - "keywords": ["Alpha", "Bravo", "Charlie", "Delta"], + 'keywords': ['Alpha', 'Bravo', 'Charlie', 'Delta'], 'isAvailable': true, 'id': 'watch1' }; @@ -1196,19 +1174,19 @@ describe(chalk.blue('service personalization test started...'), function () { it('t24 should be able to create a fieldMask personalization rule, post data and get response in specific format', function (done) { // Setup personalization rule var ruleForMobile = { - "modelName": "ProductCatalog", - "personalizationRule": { - "fieldMask": { - "modelNo": { - "pattern": "([0-9]{3})([0-9]{3})([0-9]{4})", - "maskCharacter": "X", - "format": "($1) $2-$3", - "mask": ['$3'] + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'fieldMask': { + 'modelNo': { + 'pattern': '([0-9]{3})([0-9]{3})([0-9]{4})', + 'maskCharacter': 'X', + 'format': '($1) $2-$3', + 'mask': ['$3'] } } }, - "scope": { - "region": "us" + 'scope': { + 'region': 'us' } }; @@ -1224,10 +1202,10 @@ describe(chalk.blue('service personalization test started...'), function () { 'value': 89000, 'currency': 'inr' }, - "keywords": ["Alpha", "Bravo"], + 'keywords': ['Alpha', 'Bravo'], 'isAvailable': true, 'id': 'watch2', - "modelNo": "1233567891" + 'modelNo': '1233567891' }; api.post(productCatalogUrl + '?access_token=' + accessToken) @@ -1276,19 +1254,19 @@ describe(chalk.blue('service personalization test started...'), function () { it('t26 should be able to create a fieldMask personalization rule, post data and get response in specific format', function (done) { // Setup personalization rule var ruleForMobile = { - "modelName": "ProductCatalog", - "personalizationRule": { - "fieldMask": { - "modelNo": { - "pattern": "([0-9]{5})([0-9]{1})([0-9]{4})", - "maskCharacter": "-", - "format": "+91 $1 $2$3", - "mask": ['$3'] + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'fieldMask': { + 'modelNo': { + 'pattern': '([0-9]{5})([0-9]{1})([0-9]{4})', + 'maskCharacter': '-', + 'format': '+91 $1 $2$3', + 'mask': ['$3'] } } }, - "scope": { - "region": "in" + 'scope': { + 'region': 'in' } }; @@ -1304,10 +1282,10 @@ describe(chalk.blue('service personalization test started...'), function () { 'value': 23400, 'currency': 'inr' }, - "keywords": ["Charlie", "India"], + 'keywords': ['Charlie', 'India'], 'isAvailable': true, 'id': 'watch3', - "modelNo": "9080706050" + 'modelNo': '9080706050' }; api.post(productCatalogUrl + '?access_token=' + accessToken) @@ -1356,18 +1334,18 @@ describe(chalk.blue('service personalization test started...'), function () { it('t28 should get result in specific format on get when fieldMask personalization rule is applied no masking', function (done) { // Setup personalization rule var ruleForMobile = { - "modelName": "ProductCatalog", - "personalizationRule": { - "fieldMask": { - "modelNo": { - "pattern": "([0-9]{5})([0-9]{1})([0-9]{4})", - "maskCharacter": "X", - "format": "+91 $1 $2$3" + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'fieldMask': { + 'modelNo': { + 'pattern': '([0-9]{5})([0-9]{1})([0-9]{4})', + 'maskCharacter': 'X', + 'format': '+91 $1 $2$3' } } }, - "scope": { - "region": "ka" + 'scope': { + 'region': 'ka' } }; @@ -1395,24 +1373,23 @@ describe(chalk.blue('service personalization test started...'), function () { }); } }); - }); it('t29 should get result on get when fieldMask personalization rule is applied and no format is given', function (done) { // Setup personalization rule var ruleForMobile = { - "modelName": "ProductCatalog", - "personalizationRule": { - "fieldMask": { - "modelNo": { - "pattern": "([0-9]{5})([0-9]{1})([0-9]{4})", - "maskCharacter": "X", - "mask": ['$3'] + 'modelName': 'ProductCatalog', + 'personalizationRule': { + 'fieldMask': { + 'modelNo': { + 'pattern': '([0-9]{5})([0-9]{1})([0-9]{4})', + 'maskCharacter': 'X', + 'mask': ['$3'] } } }, - "scope": { - "region": "kl" + 'scope': { + 'region': 'kl' } }; @@ -1440,7 +1417,6 @@ describe(chalk.blue('service personalization test started...'), function () { }); } }); - }); describe('Relation Tests - ', function () { @@ -1481,10 +1457,8 @@ describe(chalk.blue('service personalization test started...'), function () { ModelDefinition.create([CustomerModelSpec, AddressModelSpec], defContext, function (err, data) { if (err) { - done(err) - } - else { - + done(err); + } else { AddressModel = loopback.getModel('Address', defContext); CustomerModel = loopback.getModel('Customer', defContext); expect(AddressModel).to.not.be.undefined; @@ -1492,7 +1466,6 @@ describe(chalk.blue('service personalization test started...'), function () { done(); } }); - }); before('setup data', function (done) { @@ -1529,8 +1502,7 @@ describe(chalk.blue('service personalization test started...'), function () { CustomerModel.create(customerData, {}, function (err) { if (err) { done(err); - } - else { + } else { done(); } }); @@ -1579,7 +1551,6 @@ describe(chalk.blue('service personalization test started...'), function () { expect(results[0].billingAddress).keys('city', 'state', 'lane'); expect(results[0]).to.include.keys('name', 'age', 'billingAddress', 'id'); done(); - }); }); }); @@ -1598,7 +1569,6 @@ describe(chalk.blue('service personalization test started...'), function () { }; PersonalizationRule.create(ruleForAndroid, defContext, function (err, rule) { - debugger; if (err) { throw new Error(err); } @@ -1630,7 +1600,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'modelName': 'ProductCatalog123456', 'personalizationRule': { 'postCustomFunction': { - 'functionName': 'customFn', + 'functionName': 'customFn' } }, 'scope': { @@ -1641,9 +1611,8 @@ describe(chalk.blue('service personalization test started...'), function () { PersonalizationRule.create(ruleForAndroid, function (err, rule) { if (err) { return done(); - } else { - return done(new Error('Model doesn\'t exist, but still PersonalizationRule created')); } + return done(new Error('Model doesn\'t exist, but still PersonalizationRule created')); }); }); @@ -1653,7 +1622,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'modelName': 'ProductCatalog', 'personalizationRule': { 'postCustomFunction': { - 'functionName': 'customFn123', + 'functionName': 'customFn123' } }, 'scope': { @@ -1664,9 +1633,8 @@ describe(chalk.blue('service personalization test started...'), function () { PersonalizationRule.create(ruleForAndroid, function (err, rule) { if (err) { return done(); - } else { - return done(new Error('Function doesn\'t exist, but still PersonalizationRule created')); } + return done(new Error('Function doesn\'t exist, but still PersonalizationRule created')); }); }); @@ -1676,7 +1644,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'modelName': 'ProductCatalog', 'personalizationRule': { 'postCustomFunction': { - 'functionName': 'customFn', + 'functionName': 'customFn' } }, 'scope': { @@ -1708,7 +1676,7 @@ describe(chalk.blue('service personalization test started...'), function () { 'modelName': 'ProductCatalog', 'personalizationRule': { 'preCustomFunction': { - 'functionName': 'hashReqBody', + 'functionName': 'hashReqBody' } }, 'scope': { @@ -1746,9 +1714,7 @@ describe(chalk.blue('service personalization test started...'), function () { }); }); }); - }); - }); From 8256a3ba09f50582ddb2603e29292a357d4e6fc3 Mon Sep 17 00:00:00 2001 From: vamsee Date: Thu, 23 Jan 2020 14:32:26 +0530 Subject: [PATCH 15/15] commit for version 2.2.0 --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index ef2d4fd..8cc5ddc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oe-service-personalization", - "version": "2.1.0", + "version": "2.2.0", "description": "oe-cloud modularization project", "engines": { "node": ">=6" @@ -17,9 +17,9 @@ "assertion-error": "1.1.0", "async": "2.6.1", "lodash": "4.17.14", - "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#master", - "oe-expression": "git+http://evgit/oecloud.io/oe-expression.git#master", - "oe-personalization": "git+http://evgit/oecloud.io/oe-personalization.git#master" + "oe-cloud": "git+http://evgit/oecloud.io/oe-cloud.git#2.2.0", + "oe-expression": "git+http://evgit/oecloud.io/oe-expression.git#2.2.0", + "oe-personalization": "git+http://evgit/oecloud.io/oe-personalization.git#2.2.0" }, "devDependencies": { "babel-eslint": "7.2.3", @@ -34,9 +34,9 @@ "istanbul": "0.4.5", "md5": "^2.2.1", "mocha": "5.2.0", - "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#master", - "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#master", - "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#master", + "oe-connector-mongodb": "git+http://evgit/oecloud.io/oe-connector-mongodb.git#2.2.0", + "oe-connector-oracle": "git+http://evgit/oecloud.io/oe-connector-oracle.git#2.2.0", + "oe-connector-postgresql": "git+http://evgit/oecloud.io/oe-connector-postgresql.git#2.2.0", "superagent-defaults": "0.1.14", "supertest": "3.4.2" },