diff --git a/api-docs.yml b/api-docs.yml index e1f5db50..f81667a4 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -72,6 +72,7 @@ paths: items: $ref: '#/components/schemas/Service' description: successful response + post: tags: - services @@ -970,6 +971,21 @@ paths: application/json: schema: description: successful response + /report: + get: + tags: + - report + description: retrieves a report of total services, users, etc + responses: + 200: + description: report + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Report' + description: report components: securitySchemes: @@ -1113,6 +1129,25 @@ components: type: array items: type: string + Report: + title: Report + type: object + properties: + totalServices: + type: integer + activeServices: + type: integer + draftServices: + type: integer + archiveServices: + type: integer + users: + type: integer + systems: + type: integer + totalTransactions: + type: integer + tags: - name: services description: '' diff --git a/app.js b/app.js index a69f6ae3..99b5d5a7 100644 --- a/app.js +++ b/app.js @@ -23,6 +23,7 @@ const System = require('./models/common/System'); const MQService = require('./models/mq/MQService'); const constants = require('./lib/util/constants'); const fuseHelper = require('./lib/util/fuse'); +const reportingRouter = require('./routes/report'); global.__basedir = __dirname; // connect to database @@ -174,6 +175,7 @@ function init() { const recorderController = require('./controllers/recorderController'); app.use('/recording',recorder.recordingRouter); app.use('/api/recording',recorder.apiRouter); + app.use('/api/report/',reportingRouter.router); const mqController = require('./controllers/mqController'); mqController.registerAllMQServices(); diff --git a/controllers/reportingController.js b/controllers/reportingController.js new file mode 100644 index 00000000..45cba9c4 --- /dev/null +++ b/controllers/reportingController.js @@ -0,0 +1,236 @@ +const MQService = require('../models/mq/MQService'); +const Service = require('../models/http/Service'); +//const Recording = require('../models/http/Recording'); +const User = require('../models/common/User'); +const System = require('../models/common/System'); +const DraftService = require ('../models/common/DraftService'); +const Archive = require ('../models/common/Archive'); + + +function getAllServicesByGroups(){ + return new Promise( + function(resolve, reject){ + Service.aggregate( + { + $group:{ + _id:"$sut.name", + totalServices: + { + $sum:1 + } + } + },{ + $project: + { + sut:"$_id", + services:"$totalServices", + _id:false + } + } + + ).then(function(result){ + resolve(result); + }).catch(function(err){ + reject(err); + }); + } + ); +} + +function getTotalTransactionCount(){ + + return new Promise( + function(resolve, reject){ + Service.aggregate( + { + $group:{_id:null,totalTransactions: {$sum:"$txnCount"}} + } + ).then(function(result){ + resolve(result[0].totalTransactions); + }) + .catch(function(err){ + reject(err); + }); + + + + } + ); + + + + +} + + +/** + * Returns a promise that returns the # of total Services+MQServices. Does not include archive/drafts + * @return A promise that returns the # of total Services+MQServices + */ +function getCountOfAllServices(){ + return new Promise(function(resolve,reject){ + Service.count({},function(err,serviceCount){ + if(err) + reject(err); + else{ + MQService.count({},function(err,mqServiceCount){ + if(err) + reject(err); + else{ + resolve(mqServiceCount+serviceCount); + } + }); + } + }); + }); +} + +/** + * Returns a promise that returns the # of active Services+MQServices. Does not include archive/drafts + * @return A promise that returns the # of active Services+MQServices + */ +function getCountOfActiveServices(){ + return new Promise(function(resolve,reject){ + Service.count({running:true},function(err,serviceCount){ + if(err) + reject(err); + else{ + MQService.count({running:true},function(err,mqServiceCount){ + if(err) + reject(err); + else{ + resolve(mqServiceCount+serviceCount); + } + }); + } + }); + }); +} + + +/** + * Returns a promise that evaluates to the # of draft services + */ +function getCountOfDraftServices(){ + return new Promise(function(resolve,reject){ + DraftService.count({}, + function(err,count){ + if(err) + reject(err); + else + resolve(count); + + + } + ); + }); +} + +/** + * Returns a promise that evaluates to the # of archive services + */ +function getCountOfArchiveServices(){ + return new Promise(function(resolve,reject){ + Archive.count({}, + function(err,count){ + if(err) + reject(err); + else + resolve(count); + + + } + ); + }); +} + +/** + * Returns a promise that evaluates to the # of users + */ +function getCountOfUsers(){ + return new Promise(function(resolve,reject){ + User.count({}, + function(err,count){ + if(err) + reject(err); + else + resolve(count); + + + } + ); + }); +} + +/** + * Returns a promise that evaluates to the # of Systems + */ +function getCountOfSystems(){ + return new Promise(function(resolve,reject){ + System.count({}, + function(err,count){ + if(err) + reject(err); + else + resolve(count); + + + } + ); + }); +} + +/** + * Runs + returns a full report + * @param {*} req express req + * @param {*} rsp express rsp + * @param {*} next next middleware + */ +function fullReport(req,rsp,next){ + var report = {}; + var promises = []; + var promiseLabels = []; + + //Build list of promises + promises.push(getCountOfAllServices()); + promiseLabels.push("totalServices"); + + promises.push(getCountOfActiveServices()); + promiseLabels.push("activeServices"); + + promises.push(getCountOfDraftServices()); + promiseLabels.push("draftServices"); + + promises.push(getCountOfArchiveServices()); + promiseLabels.push("archiveServices"); + + promises.push(getCountOfUsers()); + promiseLabels.push("users"); + + promises.push(getCountOfSystems()); + promiseLabels.push("systems"); + + promises.push(getTotalTransactionCount()); + promiseLabels.push("totalTransactions"); + + promises.push(getAllServicesByGroups()); + promiseLabels.push("servicesByGroup"); + + Promise.all(promises).then( + function(vals){ + for(let i = 0; i < vals.length; i++){ + report[promiseLabels[i]] = vals[i]; + } + rsp.json(report); + } + , + function(err){ + handleError(err,rsp,500); + } + ); + +} + +module.exports = { + fullReport : fullReport +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index f39c6b39..d0a4c8eb 100644 --- a/public/index.html +++ b/public/index.html @@ -125,7 +125,8 @@

Operations:

-

{{ op.verb }} {{ mockiatoHost + virt.baseUrl + op.path }}

+

{{ op.verb }} {{ mockiatoHost + virt.baseUrl + op.path }}

+

{{ op.verb }} {{ mockiatoHost + virt.baseUrl + op.path + op.queries }}

Required Headers: Name = Content-Type | Value = application/json

Note: if you included a request payload for DELETE, be sure to use the required headers in your request: Name = Content-Type | Value = application/json


diff --git a/public/js/app/controllers.js b/public/js/app/controllers.js index 3f5f48fa..59fc6a2e 100644 --- a/public/js/app/controllers.js +++ b/public/js/app/controllers.js @@ -27,9 +27,9 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f }; }]) - .controller("myMenuAppController", ['$scope', 'apiHistoryService', 'sutService', 'authService', 'suggestionsService', 'helperFactory', 'ctrlConstants','modalService', 'mqInfoFactory', + .controller("myMenuAppController", ['$scope', 'apiHistoryService', 'sutService', 'authService', 'suggestionsService', 'helperFactory', 'commonCodeFactory','ctrlConstants','modalService', 'mqInfoFactory', - function ($scope, apiHistoryService, sutService, authService, suggestionsService, helperFactory, ctrlConstants, modalService, mqInfoFactory) { + function ($scope, apiHistoryService, sutService, authService, suggestionsService, helperFactory, commonCodeFactory, ctrlConstants, modalService, mqInfoFactory) { $scope.canEdit = function(){ return true; } $scope.myUser = authService.getUserInfo().username; $scope.canChangeType = true; @@ -45,11 +45,12 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f id: 0 }], reqHeadersArr: [{ - id: 0, + id: 0, 'k': " " }], resHeadersArr: [{ - id: 0 - }] + id: 0, 'k': " " + }], + resStatus: " " }]; $scope.statusCodes = suggestionsService.getStatusCodes(); @@ -72,46 +73,11 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f }); $scope.publishservice = function (servicevo) { - - var i = servicevo.rawpairs.length; - while(i--){ - /* handle blank request payload - when you edit and make request payload empty - then request payload becomes empty string so duplicate request check wil not work. */ - if( servicevo.rawpairs[i].requestpayload == '' || servicevo.rawpairs[i].requestpayload === null){ - servicevo.rawpairs[i].requestpayload = undefined; - } - // handeling GET method without requestpayload - if(servicevo.rawpairs[i].method!== 'GET') - { - servicevo.rawpairs[i].getPayloadRequired = false; - } - - if(servicevo.rawpairs[i].method === 'GET'&& servicevo.rawpairs[i].getPayloadRequired === false){ - servicevo.rawpairs[i].requestpayload = undefined; - } - } - //handle blank query params in rrpairs - servicevo.rawpairs.forEach(function(rrpair){ - var i = rrpair.queriesArr.length; - while(i--){ - if( rrpair.queriesArr[i].k == '' ){ - rrpair.queriesArr[i]={id: rrpair.queriesArr[i].id}; - } - } - }); - //handle blank Request Headers in rrpairs - servicevo.rawpairs.forEach(function(rrpair){ - var i = rrpair.reqHeadersArr.length; - while(i--){ - if(!rrpair.reqHeadersArr[i].k || rrpair.reqHeadersArr[i].k == ''){ - rrpair.reqHeadersArr[i]={id: rrpair.reqHeadersArr[i].id}; - } - } - }); try { + servicevo = commonCodeFactory.modifyServicevoBeforePublish(servicevo); if (helperFactory.isDuplicateReq(servicevo)) { $('#genricMsg-dialog').find('.modal-title').text(ctrlConstants.DUP_REQ_ERR_TITLE); - $('#genricMsg-dialog').find('.modal-body').text(ctrlConstants.DUP_REQ_ERR_BODY); + $('#genricMsg-dialog').find('.modal-body').html(ctrlConstants.DUP_REQ_ERR_BODY); $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.DUPLICATE_CONFIRM_FOOTER); $('#genricMsg-dialog').modal('toggle'); } else { @@ -186,14 +152,12 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f }]) - .controller("viewRecorderController", ['$scope', '$http', '$routeParams', 'apiHistoryService', 'feedbackService', 'suggestionsService', 'helperFactory', 'ctrlConstants', '$timeout', 'authService', - function ($scope, $http, $routeParams, apiHistoryService, feedbackService, suggestionsService, helperFactory, ctrlConstants, $timeout, authService) { + .controller("viewRecorderController", ['$scope', '$http', '$routeParams', 'apiHistoryService', 'feedbackService', 'suggestionsService', 'helperFactory', 'commonCodeFactory','ctrlConstants', '$timeout', 'authService', + function ($scope, $http, $routeParams, apiHistoryService, feedbackService, suggestionsService, helperFactory, commonCodeFactory,ctrlConstants, $timeout, authService) { $scope.statusCodes = suggestionsService.getStatusCodes(); $scope.possibleHeaders = suggestionsService.getPossibleHeaders(); var totalRRPairs = 0; - - function processRRPairs(rrpairs) { var rrpairsRaw = []; var rrid = 0; @@ -360,10 +324,15 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f return true; } else { - return false; } }; + if(!newsutlist.includes($scope.servicevo.sut.name)){ + $('#genricMsg-dialog').find('.modal-title').html(ctrlConstants.EDIT_RECORDING_INFO_TITLE); + $('#genricMsg-dialog').find('.modal-body').html("You can\'t edit this recording because you aren\'t part of the group "+$scope.servicevo.sut.name+"."); + $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.EDIT_SERV_INFO_FOOTER); + $('#genricMsg-dialog').modal('toggle'); + } }) .catch(function (err) { @@ -372,9 +341,10 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f $scope.publishService = function (servicevo) { try { + servicevo = commonCodeFactory.modifyServicevoBeforePublish(servicevo); if (helperFactory.isDuplicateReq(servicevo)) { $('#genricMsg-dialog').find('.modal-title').text(ctrlConstants.DUP_REQ_ERR_TITLE); - $('#genricMsg-dialog').find('.modal-body').text(ctrlConstants.DUP_REQ_ERR_BODY); + $('#genricMsg-dialog').find('.modal-body').html(ctrlConstants.DUP_REQ_ERR_BODY); $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.DUPLICATE_CONFIRM_FOOTER); $('#genricMsg-dialog').modal('toggle'); } else { @@ -560,8 +530,8 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f this.getService(); }]) - .controller("showDraftController", ['$scope', '$q', '$http', '$routeParams', 'apiHistoryService', 'feedbackService', 'suggestionsService', 'helperFactory', 'ctrlConstants', 'sutService', 'authService', 'modalService', - function ($scope, $q, $http, $routeParams, apiHistoryService, feedbackService, suggestionsService, helperFactory, ctrlConstants, sutService, authService, modalService) { + .controller("showDraftController", ['$scope', '$q', '$http', '$routeParams', 'apiHistoryService', 'feedbackService', 'suggestionsService', 'helperFactory', 'commonCodeFactory','ctrlConstants', 'sutService', 'authService', 'modalService', + function ($scope, $q, $http, $routeParams, apiHistoryService, feedbackService, suggestionsService, helperFactory, commonCodeFactory, ctrlConstants, sutService, authService, modalService) { $scope.showDates = true; $scope.statusCodes = suggestionsService.getStatusCodes(); $scope.possibleHeaders = suggestionsService.getPossibleHeaders(); @@ -785,46 +755,11 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f $scope.updateService = function (servicevo) { - /* handle blank request payload - when you edit and make request payload empty - then request payload becomes empty string so duplicate request check wil not worker. */ - var i = servicevo.rawpairs.length; - while(i--){ - if( servicevo.rawpairs[i].requestpayload == '' || servicevo.rawpairs[i].requestpayload === null){ - servicevo.rawpairs[i].requestpayload = undefined; - } - // handeling GET method without requestpayload - if(servicevo.rawpairs[i].method!== 'GET') - { - servicevo.rawpairs[i].getPayloadRequired = false; - } - - if(servicevo.rawpairs[i].method === 'GET'&& servicevo.rawpairs[i].getPayloadRequired === false){ - servicevo.rawpairs[i].requestpayload = undefined; - } - } - - //handle blank query params in rrpairs. if you provide query param and then make it blank. - servicevo.rawpairs.forEach(function(rrpair){ - var i = rrpair.queriesArr.length; - while(i--){ - if( rrpair.queriesArr[i].k == '' ){ - rrpair.queriesArr[i]={id: rrpair.queriesArr[i].id}; - } - } - }); - //handle blank Request Headers in rrpairs - servicevo.rawpairs.forEach(function(rrpair){ - var i = rrpair.reqHeadersArr.length; - while(i--){ - if(!rrpair.reqHeadersArr[i].k || rrpair.reqHeadersArr[i].k == ''){ - rrpair.reqHeadersArr[i]={id: rrpair.reqHeadersArr[i].id}; - } - } - }); try { + servicevo = commonCodeFactory.modifyServicevoBeforePublish(servicevo); if (helperFactory.isDuplicateReq(servicevo)) { $('#genricMsg-dialog').find('.modal-title').text(ctrlConstants.DUP_REQ_ERR_TITLE); - $('#genricMsg-dialog').find('.modal-body').text(ctrlConstants.DUP_REQ_ERR_BODY); + $('#genricMsg-dialog').find('.modal-body').html(ctrlConstants.DUP_REQ_ERR_BODY); $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.DUPLICATE_CONFIRM_FOOTER); $('#genricMsg-dialog').modal('toggle'); } else { @@ -974,6 +909,12 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f return false; } }; + if(!newsutlist.includes($scope.servicevo.sut.name)){ + $('#genricMsg-dialog').find('.modal-title').html(ctrlConstants.EDIT_RECORDING_INFO_TITLE); + $('#genricMsg-dialog').find('.modal-body').html("You can\'t edit this recording because you aren\'t part of the group "+$scope.servicevo.sut.name+"."); + $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.EDIT_SERV_INFO_FOOTER); + $('#genricMsg-dialog').modal('toggle'); + } }) .catch(function (err) { @@ -1156,8 +1097,8 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f }); $scope.pollForRRPairs(); }]) - .controller("updateController", ['$scope', '$q', '$http', '$routeParams', 'apiHistoryService', 'feedbackService', 'suggestionsService', 'helperFactory', 'ctrlConstants', 'sutService', 'authService', "$location",'modalService', 'mqInfoFactory', - function ($scope, $q, $http, $routeParams, apiHistoryService, feedbackService, suggestionsService, helperFactory, ctrlConstants, sutService, authService, $location, modalService, mqInfoFactory) { + .controller("updateController", ['$scope', '$q', '$http', '$routeParams', 'apiHistoryService', 'feedbackService', 'suggestionsService', 'helperFactory', 'commonCodeFactory', 'ctrlConstants', 'sutService', 'authService', "$location",'modalService', 'mqInfoFactory', + function ($scope, $q, $http, $routeParams, apiHistoryService, feedbackService, suggestionsService, helperFactory, commonCodeFactory, ctrlConstants, sutService, authService, $location, modalService, mqInfoFactory) { $scope.showDates = true; $scope.statusCodes = suggestionsService.getStatusCodes(); $scope.possibleHeaders = suggestionsService.getPossibleHeaders(); @@ -1257,10 +1198,15 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f return true; } else { - return false; } }; + if(!newsutlist.includes($scope.servicevo.sut.name)){ + $('#genricMsg-dialog').find('.modal-title').html(ctrlConstants.EDIT_SERV_INFO_TITLE); + $('#genricMsg-dialog').find('.modal-body').html("You can\'t edit this service because you aren\'t part of the group "+$scope.servicevo.sut.name+". You can request access from user "+$scope.servicevo.lastUpdateUser+"."); + $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.EDIT_SERV_INFO_FOOTER); + $('#genricMsg-dialog').modal('toggle'); + } }) .catch(function (err) { @@ -1381,64 +1327,16 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f }; this.getService(); - - - - $scope.viewRecorded = function () { $location.path("/update/" + $scope.servicevo.id + "/recorded") } - - $scope.updateService = function (servicevo) { - //handle blank query params in rrpairs - servicevo.rawpairs.forEach(function(rrpair){ - var i = rrpair.queriesArr.length; - while(i--){ - if( rrpair.queriesArr[i].k == '' ){ - rrpair.queriesArr[i]={id: rrpair.queriesArr[i].id}; - } - } - }); - /* handle blank request payload - when you edit and make request payload empty - then request payload becomes empty string so duplicate request check wil not work. */ - var i = servicevo.rawpairs.length; - while(i--){ - if( servicevo.rawpairs[i].requestpayload == '' || servicevo.rawpairs[i].requestpayload === null){ - servicevo.rawpairs[i].requestpayload = undefined; - } - // handeling GET method without requestpayload - if(servicevo.rawpairs[i].method!== 'GET') - { - servicevo.rawpairs[i].getPayloadRequired = false; - } - - if(servicevo.rawpairs[i].method === 'GET'&& servicevo.rawpairs[i].getPayloadRequired === false){ - servicevo.rawpairs[i].requestpayload = undefined; - } - } - - if($scope.servicevo.delayMax === null){ - $scope.servicevo.delayMax = 0; - } - if($scope.servicevo.delay === null){ - $scope.servicevo.delay = 0; - } - - //handle blank Request Headers in rrpairs - servicevo.rawpairs.forEach(function(rrpair){ - var i = rrpair.reqHeadersArr.length; - while(i--){ - if(!rrpair.reqHeadersArr[i].k || rrpair.reqHeadersArr[i].k == ''){ - rrpair.reqHeadersArr[i]={id: rrpair.reqHeadersArr[i].id}; - } - } - }); try { + servicevo = commonCodeFactory.modifyServicevoBeforePublish(servicevo); if (helperFactory.isDuplicateReq(servicevo)) { $('#genricMsg-dialog').find('.modal-title').text(ctrlConstants.DUP_REQ_ERR_TITLE); - $('#genricMsg-dialog').find('.modal-body').text(ctrlConstants.DUP_REQ_ERR_BODY); + $('#genricMsg-dialog').find('.modal-body').html(ctrlConstants.DUP_REQ_ERR_BODY); $('#genricMsg-dialog').find('.modal-footer').html(ctrlConstants.DUPLICATE_CONFIRM_FOOTER); $('#genricMsg-dialog').modal('toggle'); } else { @@ -1453,8 +1351,6 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f } }; - - $scope.serviceInfo = function () { console.log($routeParams.id); $http.get('/api/services/' + $routeParams.id) @@ -2642,7 +2538,7 @@ var ctrl = angular.module("mockapp.controllers", ['mockapp.services', 'mockapp.f //Put all the hard coding or constants here for controller. ctrl.constant("ctrlConstants", { "DUP_REQ_ERR_TITLE": "Duplicate Request Error", - "DUP_REQ_ERR_BODY": "Two Requests are same. Either change request data or relative path of duplicate requests.", + "DUP_REQ_ERR_BODY": "Two Requests are same. These RR Pairs are highlighted with below red colour heading.

Duplicate Req/Res Pair


Please make sure there is no duplicate request before publish.", "PUB_FAIL_ERR_TITLE": "Publish Failure Error", "PUB_FAIL_ERR_BODY": "Please ensure your request / response pairs are well formed.", "DUP_RECORDER_PATH_TITLE": "Publish Failure: Duplicate Path", @@ -2684,5 +2580,8 @@ ctrl.constant("ctrlConstants", { "MRG_CONFIRM_TITLE": "Merge Confirmation", "MRG_CONFIRM_BODY": "Do you want to merge this RRPair into the service?", "MRG_CONFIRM_FOOTER": '', - "SERVICE_RESTORE_FAIL_TITLE" : "Restore Fail" + "SERVICE_RESTORE_FAIL_TITLE" : "Restore Fail", + "EDIT_SERV_INFO_TITLE": "Edit Service Info", + "EDIT_SERV_INFO_FOOTER": '', + "EDIT_RECORDING_INFO_TITLE": "Edit Recording Info" }); diff --git a/public/js/app/controllers/rrPairs.js b/public/js/app/controllers/rrPairs.js index 8a9d404b..f46ffd49 100644 --- a/public/js/app/controllers/rrPairs.js +++ b/public/js/app/controllers/rrPairs.js @@ -1,6 +1,10 @@ var ctrl = angular.module("mockapp.controllers") - .controller("rrPairController", ['suggestionsService', '$scope', 'ctrlConstants','domManipulationService','utilityService', - function (suggestionsService, $scope, ctrlConstants,domManipulationService,utilityService){ + .controller("rrPairController", ['suggestionsService', '$scope', '$location', 'ctrlConstants','domManipulationService','utilityService', + function (suggestionsService, $scope, $location, ctrlConstants,domManipulationService,utilityService){ + //To Check if it's for service cration page or service update page. + /* if ($location.path().slice(1) === 'addservice') { + $scope.isCreateServPage=true; + } */ $scope.addNewRRPair = function () { var newItemNo = $scope.servicevo.rawpairs.length; $scope.servicevo.rawpairs.push({ @@ -9,11 +13,13 @@ var ctrl = angular.module("mockapp.controllers") id: 0 }], reqHeadersArr: [{ - id: 0 - }], + id: 0, 'k': " " + }], resHeadersArr: [{ - id: 0 - }] + id: 0, 'k': " " + }], + resStatus: " ", + isDup: false }); if (newItemNo > 10){ $scope.loadMore(); @@ -73,7 +79,7 @@ var ctrl = angular.module("mockapp.controllers") $scope.addNewReqHeader = function (rr) { var newItemNo = rr.reqHeadersArr.length; - rr.reqHeadersArr.push({ 'id': newItemNo }); + rr.reqHeadersArr.push({ 'id': newItemNo, 'k': " " }); }; $scope.removeReqHeader = function (rr, index) { @@ -82,7 +88,7 @@ var ctrl = angular.module("mockapp.controllers") $scope.addNewResHeader = function (rr) { var newItemNo = rr.resHeadersArr.length; - rr.resHeadersArr.push({ 'id': newItemNo }); + rr.resHeadersArr.push({ 'id': newItemNo, 'k': " " }); }; $scope.removeResHeader = function (rr, index) { diff --git a/public/js/app/factories.js b/public/js/app/factories.js index 6c63cf92..9ea0eaa1 100644 --- a/public/js/app/factories.js +++ b/public/js/app/factories.js @@ -195,6 +195,57 @@ fact.factory('mqInfoFactory', ['$http', function($http) { }; }]); +//Modify serviceVO before Publish - Pradeep +fact.factory('commonCodeFactory', [function () { + return { + modifyServicevoBeforePublish: function (servicevo) { + var i = servicevo.rawpairs.length; + while(i--){ + /* handle blank request payload - when you edit and make request payload empty + then request payload becomes empty string so duplicate request check wil not work. */ + if( servicevo.rawpairs[i].requestpayload == '' || servicevo.rawpairs[i].requestpayload === null || !servicevo.rawpairs[i].hasOwnProperty('requestpayload')){ + servicevo.rawpairs[i].requestpayload = undefined; + } + /* handeling GET method without requestpayload */ + if(servicevo.rawpairs[i].method!== 'GET') + { + servicevo.rawpairs[i].getPayloadRequired = false; + } + if(servicevo.rawpairs[i].method === 'GET'&& servicevo.rawpairs[i].getPayloadRequired === false){ + servicevo.rawpairs[i].requestpayload = undefined; + } + /* handle blank query params in rrpairs. if you provide query param and then make it blank.*/ + var j = servicevo.rawpairs[i].queriesArr.length; + while(j--){ + if( servicevo.rawpairs[i].queriesArr[j].k == '' ){ + servicevo.rawpairs[i].queriesArr[j]={id: servicevo.rawpairs[i].queriesArr[j].id}; + } + } + /* handle blank Request Headers in rrpairs */ + var k = servicevo.rawpairs[i].reqHeadersArr.length; + while(k--){ + if(!servicevo.rawpairs[i].reqHeadersArr[k].k || servicevo.rawpairs[i].reqHeadersArr[k].k == ' '){ + servicevo.rawpairs[i].reqHeadersArr[k]={id: servicevo.rawpairs[i].reqHeadersArr[k].id}; + } + } + /* before publish service make isDup flag false for all rrpairs and + let the isDuplicateReq function of factories method set this flag true b + in case of duplicate*/ + servicevo.rawpairs[i].isDup=false; + } + /* handle response delay on service level. if you provide response delay and then make it blank again. */ + if(servicevo.delayMax === null){ + servicevo.delayMax = 0; + } + if(servicevo.delay === null){ + servicevo.delay = 0; + } + return servicevo; + } + }; +}]); + + //Below function is complex one. Any change will break Duplicate Req check. - Pradeep fact.factory('helperFactory', [function () { return { @@ -254,6 +305,8 @@ fact.factory('helperFactory', [function () { } if (isAnyReqPairDuplicate) { isSameReq = true; + servicevo.rawpairs[i].isDup=true; + servicevo.rawpairs[j].isDup=true; break LOOP1; } } diff --git a/public/partials/includes/rrPairs.html b/public/partials/includes/rrPairs.html index fd7b0ea2..a4d8967f 100644 --- a/public/partials/includes/rrPairs.html +++ b/public/partials/includes/rrPairs.html @@ -1,268 +1,268 @@
-
-
-
-
-

Request / Response Pair

-
- -
- -
- -
- -
-
- -
- -
- -
-
- -
- -
-
- +
+
+
+
+

Duplicate Req/Res Pair

+

Request / Response Pair

+
+
+ +
+ +
+
-
- -
- -
-
- + +
+ +
+
-
- -
- -
-
-
-
-
- -
- -
- -
- -
- -
- -
- -
-
-
+ +
+ +
+
+ +
+
-
- -
- + +
+
-
- - - +
+
- -
- -
-
+ +
+ +
+

-
-
-
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+
- -
- -
- -
- -
- -
- -
-
-
+
+
-
- -
- + +
+ +
+
+ + + +
+
+
+ +
+
- +
+
+
+
+
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+
- -
- -
- -
-
- - + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
-
-
-
-
- +
+
+
+ +
-
- - -
- -
-
+ + +
+ +
+
+
-
- -
- -
-
-
-
-
-
+ +
+ +
+
+
+
+
+
+
+
+ +
+ +
+ + +
+ +
+ +
+
- -
- -
- - -
- -
- -
- -
-
-
-
-
- -
- -
- +
+
-
- - + +
+ +
+ +
+
+ + +
+ + +
+
+ + Show more pairs +
- - -
-
- - Show more pairs - -
- -
\ No newline at end of file + + \ No newline at end of file diff --git a/public/partials/recordedInvokePairs.html b/public/partials/recordedInvokePairs.html index c3028c4f..5ee895c9 100644 --- a/public/partials/recordedInvokePairs.html +++ b/public/partials/recordedInvokePairs.html @@ -1,6 +1,6 @@

Merge Recorded Live Invocation Request/Responses

-

You are unable to edit this service because you aren't part of the group "{{servicevo.sut.name}}". You can request access - from the user: {{servicevo.lastUpdateUser}}.

+
diff --git a/public/partials/updateForm.html b/public/partials/updateForm.html index 67cfb239..224f082c 100644 --- a/public/partials/updateForm.html +++ b/public/partials/updateForm.html @@ -1,5 +1,5 @@

Update Mock Service

-

You are unable to edit this service because you aren't part of the group "{{servicevo.sut.name}}". You can request access from the user: {{servicevo.lastUpdateUser}}.

+
diff --git a/public/partials/viewRecorder.html b/public/partials/viewRecorder.html index 291229b6..fe0e8f14 100644 --- a/public/partials/viewRecorder.html +++ b/public/partials/viewRecorder.html @@ -1,5 +1,5 @@

Finalize Recording

-

You are unable to edit this service because you aren't part of the group "{{servicevo.sut.name}}".

+
diff --git a/routes/report.js b/routes/report.js new file mode 100644 index 00000000..ec09dc27 --- /dev/null +++ b/routes/report.js @@ -0,0 +1,9 @@ +const express = require('express'); +const router = express.Router(); +const reportingController = require('../controllers/reportingController'); + +router.get("/",reportingController.fullReport); + +module.exports = { + router : router +} \ No newline at end of file diff --git a/tests/resources/random/Random_Test_Base_Service.json b/tests/resources/random/Random_Test_Base_Service.json new file mode 100644 index 00000000..cc6bcaa8 --- /dev/null +++ b/tests/resources/random/Random_Test_Base_Service.json @@ -0,0 +1,64 @@ +{ + "updatedAt": "2019-02-14T16:39:01.206Z", + "createdAt": "2019-02-14T16:39:01.206Z", + "sut": { + "name": "RecordTest", + "__v": 0, + "members": [ + "jsmith" + ] + }, + "name": "Record Test Base", + "type": "REST", + "basePath": "/recordme", + "lastUpdateUser": { + "uid": "jsmith", + "mail": "john_smith@asd.com", + "_id": "5c6599a5b75e2abea8145734" + }, + "liveInvocation": { + "liveFirst": false, + "recordedRRPairs": [], + "record": false, + "failStrings": [ + "" + ], + "failStatusCodes": [ + null + ] + }, + "running": true, + "txnCount": 0, + "delayMax": 200, + "delay": 100, + "rrpairs": [ + { + "verb": "POST", + "payloadType": "JSON", + "reqHeaders": { + "Content-Type": "application/json" + }, + "reqData": { + "test": "one", + "test2:": true, + "test3:": 12345, + "testObj:": { + "innerTest:": "testo", + "innterTest2:": "testooo" + } + }, + "resHeaders": { + "Content-Type": "application/json" + }, + "resData": { + "response": "NAME : {{random:name:nationality,it:middle_initial,true}}" + }, + "reqDataString": "{\"test\":\"one\",\"test2:\":true,\"test3:\":12345,\"testObj:\":{\"innerTest:\":\"testo\",\"innterTest2:\":\"testooo\"}}", + "resDataString": "{\"response\":\"This is a good response\"}", + "resStatus": 200 + } + ], + "matchTemplates": [ + "" + ] +} \ No newline at end of file diff --git a/tests/resources/random/random_test_rec-req.json b/tests/resources/random/random_test_rec-req.json new file mode 100644 index 00000000..aa4469e2 --- /dev/null +++ b/tests/resources/random/random_test_rec-req.json @@ -0,0 +1,9 @@ +{ + "test": "one", + "test2:": true, + "test3:": 12345, + "testObj:": { + "innerTest:": "testo", + "innterTest2:": "testooo" + } +} \ No newline at end of file diff --git a/tests/test-random.js b/tests/test-random.js new file mode 100644 index 00000000..19a28b8f --- /dev/null +++ b/tests/test-random.js @@ -0,0 +1,115 @@ +const app = require('../app'); +const request = require('supertest').agent(app); +const test = require('./test.js'); + + + + + +let id; + +let token = '?token='; + +const resource = '/api/'; +const baseService = require('./resources/random/Random_Test_Base_Service.json'); +const serviceRequest = require('./resources/random/random_test_rec-req.json'); + +const mockUser = { + username: getRandomString(), + mail: getRandomString() + '@noreply.com', + password: getRandomString() +} + +const mockGroup = { + name: getRandomString() +}; + +function getRandomString() { + return Math.random().toString(36).substring(2, 15); +} + + +baseService.sut = mockGroup; + +describe('Random Tests', function() { + this.timeout(15000); + + + describe('Setup', function() { + it('Registers User', function(done) { + request + .post('/register') + .send(mockUser) + .expect(302) + .end(done); + }); + it('Gets the token', function(done) { + request + .post('/api/login') + .send({ username: mockUser.username, password: mockUser.password }) + .expect(200) + .expect(function(res) { + token = token + res.body.token; + }).end(done); + }); + it('Creates a group', function(done) { + request + .post('/api/systems' + token) + .send(mockGroup) + .expect(200) + .end(done); + }); + it('Creates the base service', function(done) { + request + .post('/api/services' + token) + .send(baseService) + .expect(200) + .expect(function(res){ + id = res.body._id; + }) + .end(done); + }); + }); + + + + + + describe('Request against Random',function(){ + it('Returns a good response',function(done){ + request + .post('/virtual/' + mockGroup.name +baseService.basePath) + .send(serviceRequest) + .expect(200,done); + }); + }); + + + + + describe('Cleanup', function() { + + it('Deletes the base service', function(done) { + request + .delete('/api/services/' + id + token) + .expect(200) + .end(done); + }); + it('Deletes group', function(done) { + request + .delete('/api/systems/' + mockGroup.name + token) + .expect(200) + .end(done); + }); + it('Deletes user', function(done) { + request + .delete('/api/users/' + mockUser.username + token) + .expect(200) + .end(done); + }); + + }); + + +}); + diff --git a/tests/test-report.js b/tests/test-report.js new file mode 100644 index 00000000..c060a51d --- /dev/null +++ b/tests/test-report.js @@ -0,0 +1,42 @@ +const app = require('../app'); +const request = require('supertest').agent(app); +const test = require('./test.js'); + + + + + + + +const mockUser = { + username: getRandomString(), + mail: getRandomString() + '@noreply.com', + password: getRandomString() +} + +const mockGroup = { + name: getRandomString() +}; + +function getRandomString() { + return Math.random().toString(36).substring(2, 15); +} + + + +describe('Report Tests', function() { + this.timeout(15000); + describe('Report Tests',function(){ + it('Gets the full report',function(done){ + request + .get('/api/report') + .expect(200,done); + }); + }); + + + + + +}); +