From e9928b31d9e0bd73d4f33774339388f1b352eab8 Mon Sep 17 00:00:00 2001 From: Khantil Choksi Date: Sat, 17 Mar 2018 01:37:53 -0400 Subject: [PATCH] adding routes request auto generated --- checkbox_test_generation/.DS_Store | Bin 6148 -> 6148 bytes .../coverage/coverage.json | 1 + .../coverage/lcov-report/base.css | 213 +++++ .../checkbox_test_generation/index.html | 93 ++ .../mock_db/db.js.html | 179 ++++ .../mock_db/index.html | 119 +++ .../mock_db/studies.js.html | 146 ++++ .../mock_db/votes.js.html | 137 +++ .../mock_routes/admin.js.html | 806 ++++++++++++++++++ .../mock_routes/create.js.html | 422 +++++++++ .../mock_routes/index.html | 106 +++ .../mock_routes/study.js.html | 731 ++++++++++++++++ .../mock_routes/studyModel.js.html | 389 +++++++++ .../mock_routes/upload.js.html | 437 ++++++++++ .../routes/create.js.html | 398 +++++++++ .../routes/index.html | 106 +++ .../routes/study.js.html | 689 +++++++++++++++ .../routes/studyModel.js.html | 389 +++++++++ .../routes/upload.js.html | 437 ++++++++++ .../checkbox_test_generation/server.js.html | 350 ++++++++ .../checkbox_test_generation/test.js.html | 131 +++ .../coverage/lcov-report/index.html | 119 +++ .../coverage/lcov-report/prettify.css | 1 + .../coverage/lcov-report/prettify.js | 1 + .../lcov-report/sort-arrow-sprite.png | Bin 0 -> 209 bytes .../coverage/lcov-report/sorter.js | 158 ++++ checkbox_test_generation/coverage/lcov.info | 353 ++++++++ checkbox_test_generation/package.json | 20 +- checkbox_test_generation/src/constraint.js | 11 +- checkbox_test_generation/src/testgenerator.js | 19 +- checkbox_test_generation/test.js | 29 +- checkbox_test_generation/test_mock.js | 13 +- 32 files changed, 6964 insertions(+), 39 deletions(-) create mode 100644 checkbox_test_generation/coverage/coverage.json create mode 100644 checkbox_test_generation/coverage/lcov-report/base.css create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/index.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/db.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/index.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/studies.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/votes.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/admin.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/create.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/index.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/study.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/studyModel.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/upload.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/create.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/index.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/study.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/studyModel.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/upload.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/server.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/test.js.html create mode 100644 checkbox_test_generation/coverage/lcov-report/index.html create mode 100644 checkbox_test_generation/coverage/lcov-report/prettify.css create mode 100644 checkbox_test_generation/coverage/lcov-report/prettify.js create mode 100644 checkbox_test_generation/coverage/lcov-report/sort-arrow-sprite.png create mode 100644 checkbox_test_generation/coverage/lcov-report/sorter.js create mode 100644 checkbox_test_generation/coverage/lcov.info diff --git a/checkbox_test_generation/.DS_Store b/checkbox_test_generation/.DS_Store index 39c1604e2dfa35d6eea73aa2a3020b2c8e08d4de..b6f1393e4d846e143021983fe9c263befd4040cb 100644 GIT binary patch delta 97 zcmZoMXffEJ%f$G3vL4e)FR|)sGcz3pW8+#Kg=z~kV;u!k6O-CnP7V%9b+@3n(x$#y ivzIJgw*0_B1~6b`gwPCvP#Q)Z+N{F-m}M~whX4Qw=@wZ4 delta 49 zcmZoMXffEJ%f$F?vL4e)9?9xzT?-Q(1zjT(v&j#b + + + Code coverage report for checkbox_test_generation/ + + + + + + + +
+
+

+ all files checkbox_test_generation/ +

+
+
+ 100% + Statements + 7/7 +
+
+ 100% + Branches + 0/0 +
+
+ 100% + Functions + 1/1 +
+
+ 100% + Lines + 6/6 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
test.js
100%7/7100%0/0100%1/1100%6/6
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/db.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/db.js.html new file mode 100644 index 0000000..29bcca3 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/db.js.html @@ -0,0 +1,179 @@ + + + + Code coverage report for checkbox_test_generation/mock_db/db.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_db/ db.js +

+
+
+ 45.45% + Statements + 5/11 +
+
+ 0% + Branches + 0/4 +
+
+ 0% + Functions + 0/1 +
+
+ 45.45% + Lines + 5/11 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 + + +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +
var studies = require('./studies.js');
+var votes = require('./votes.js');
+var db = require('./db.js');
+ 
+ 
+db.collection = function(collect, cb){
+	try{
+		if(collect.toString().trim() === 'studies'){
+			cb(null, studies);
+ 
+		}
+		else if(collect.toString().trim() === 'votes'){
+			cb(null, votes);
+		}		
+	}
+	catch(e){
+			cb(e, '');
+	}
+};
+ 
+/*exports.findOne = function(){};
+var func_collection = function(){};
+ 
+ 
+exports.loadStudy = function(req, res) {
+    var id = req.params.id;
+    console.log('Retrieving study: ' + id);
+    db.collection('studies', function(err, collection) {
+        collection.findOne({'_id':new ObjectID(id)}, function(err, item) {
+            // don't allow token to be seen by others.
+            delete item["token"];
+            delete item["invitecode"];
+ 
+            res.send(item);
+        });
+    });
+};
+*/
+module.exports = db;
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/index.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/index.html new file mode 100644 index 0000000..47e7886 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/index.html @@ -0,0 +1,119 @@ + + + + Code coverage report for checkbox_test_generation/mock_db/ + + + + + + + +
+
+

+ all files checkbox_test_generation/mock_db/ +

+
+
+ 45.95% + Statements + 17/37 +
+
+ 0% + Branches + 0/8 +
+
+ 0% + Functions + 0/3 +
+
+ 45.95% + Lines + 17/37 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
db.js
45.45%5/110%0/40%0/145.45%5/11
studies.js
46.15%6/130%0/20%0/146.15%6/13
votes.js
46.15%6/130%0/20%0/146.15%6/13
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/studies.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/studies.js.html new file mode 100644 index 0000000..f7ad016 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/studies.js.html @@ -0,0 +1,146 @@ + + + + Code coverage report for checkbox_test_generation/mock_db/studies.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_db/ studies.js +

+
+
+ 46.15% + Statements + 6/13 +
+
+ 0% + Branches + 0/2 +
+
+ 0% + Functions + 0/1 +
+
+ 46.15% + Lines + 6/13 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 + + +  + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  + 
var votes = require('./votes.js');
+var db = require('./db.js');
+var mock_studies = require('../test_data/studies.json');
+ 
+var studies = require('./studies.js');
+ 
+studies.findOne = function(dict, cb){
+	var key = Object.keys(dict)[0];
+//	console.log(key);
+	var value = dict[key].val;
+//	console.log(value);
+//	console.log('key = ' + key + '; value = ' + value);
+	for(var m_i in mock_studies){
+		console.log( " key = " +  mock_studies[m_i][key]);
+		console.log( " val =  " + value);
+		if(mock_studies[m_i][key] == value){
+			cb(null, mock_studies[m_i]);
+		};
+	};
+ 
+};
+ 
+ 
+ 
+module.exports = studies;
+ 
+ 
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/votes.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/votes.js.html new file mode 100644 index 0000000..49cf362 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_db/votes.js.html @@ -0,0 +1,137 @@ + + + + Code coverage report for checkbox_test_generation/mock_db/votes.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_db/ votes.js +

+
+
+ 46.15% + Statements + 6/13 +
+
+ 0% + Branches + 0/2 +
+
+ 0% + Functions + 0/1 +
+
+ 46.15% + Lines + 6/13 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 + + +  + +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var studies = require('./studies.js');
+var db = require('./db.js');
+var mock_votes = require('../test_data/votes.json');
+ 
+var votes = require('./votes.js');
+ 
+ 
+votes.findOne = function(dict, cb){
+	var key = Object.keys(dict)[0];
+//	console.log(key);
+	var value = dict[key].val;
+//	console.log(value);
+//	console.log('key = ' + key + '; value = ' + value);
+	for(var m_i in mock_votes){
+		console.log( " key = " +  mock_votes[m_i][key]);
+		console.log( " val =  " + value);
+		if(mock_votes[m_i][key] == value){
+			cb(null, mock_votes[m_i]);
+		};
+	};
+};
+ 
+ 
+module.exports = votes;
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/admin.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/admin.js.html new file mode 100644 index 0000000..03ff815 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/admin.js.html @@ -0,0 +1,806 @@ + + + + Code coverage report for checkbox_test_generation/mock_routes/admin.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_routes/ admin.js +

+
+
+ 12.37% + Statements + 12/97 +
+
+ 0% + Branches + 0/38 +
+
+ 0% + Functions + 0/31 +
+
+ 12.5% + Lines + 12/96 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248  + + + + +  +  +  +  +  +  +  + +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
//var mongo = require('mongodb');
+var check = require('validator').check;
+var _ = require('underscore');
+var emailjs = require('emailjs');
+var fileService = require('./upload.js');
+ 
+class ObjectID{
+    constructor(val){
+        this.val =  val;
+    }
+}
+ 
+var db = require("../mock_db/db.js");
+ 
+ 
+/*var Server = mongo.Server,
+    Db = mongo.Db,
+    ObjectID = mongo.ObjectID;
+*/ 
+var emailServer  = emailjs.server.connect({
+   user:    "supportemail@domain.com", 
+   password:"supportpwd", 
+   host:    "smtp.gmail.com", 
+   ssl:     true
+});
+ 
+//var MongoClient = mongo.MongoClient;
+/*var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+*/
+exports.loadStudy = function(req, res) {
+    var token = req.params.token;
+    console.log(" token value" + token)
+    console.log('Retrieving study by token: ' + token);
+    db.collection('studies', function(err, collection) {
+        collection.findOne({'token':token}, function(err, item) {
+            res.send(item);
+        });
+    });
+};
+ 
+exports.openStudy = function(req, res) {
+    var token = req.body.token;
+    db.collection('studies', function(err, collection) {
+        collection.findOne({'token':token}, function(err, study) {
+            collection.update( {'_id' : study._id}, 
+                     {'$set' : {'status' : 'open'}});
+            res.send({status:'ok'});
+        });
+    });
+}
+ 
+exports.closeStudy = function(req, res) {
+    var token = req.body.token;
+    db.collection('studies', function(err, collection) {
+        collection.findOne({'token':token}, function(err, study) {
+            collection.update( {'_id' : study._id}, 
+                     {'$set' : {'status' : 'closed'}});
+            res.send({status:'ok'});
+        });
+    });
+}
+ 
+exports.download = function(req, res ) {
+    var token = req.params.token;
+    console.log(token);
+ 
+        // get surveyId, then votes matching that.
+    db.collection('studies', function(err, studyCollection) {
+        studyCollection.findOne({'token':token}, function(err, study) 
+        {
+            if( study && study.studyKind == "survey" )
+            {
+                db.collection('votes', function(err, voteCollection) {
+                    //voteCollection.find({'survey.$id':survey._id}).toArray(function(err, items) {
+                    voteCollection.find({'studyId':study._id}).toArray(function(err, items) {
+                        console.log(err || "Participants: " + items.length);
+ 
+                        for( var i=0; i < items.length; i++ )
+                        {
+                            delete items[i]['email'];
+                        }
+ 
+                        res.setHeader('Content-disposition', 'attachment; filename=download.json');
+                        res.send({votes: items});
+ 
+                    });
+                });
+            }
+            else if( study && study.studyKind == "dataStudy" )
+            {
+                db.collection('votes', function(err, voteCollection) {
+                    voteCollection.find({'studyId':study._id}).toArray(function(err, items) {
+ 
+                        var fileIds = items.map( function(elem)
+                            { 
+                                if( elem.files && elem.files.length > 0 )
+                                    return elem.files[0].fileId;
+                                else
+                                    return null; 
+                            }).filter( function(elem){ return elem != null; });
+ 
+                        console.log( fileIds );
+ 
+                        // This creates the archive and attaches files to it.
+                        fileService.readFiles( res, fileIds, function(err, archive)
+                        {
+                            for( var i=0; i < items.length; i++ )
+                            {
+                                delete items[i]['email'];
+                            }
+ 
+                            var data = JSON.stringify( items, null, 3 );
+                            // Add non-file data.
+                            archive.append( data, { name: "data.json" }, function()
+                            {
+                                console.log("appended: data");
+                            });
+ 
+                            // Signal that archive is done.
+                            archive.finalize(function(err, written) 
+                            {
+                                if (err) { throw err; }
+                                console.log(written + ' total bytes written');
+                            });
+                        });
+ 
+                    });
+                });                
+            }
+            else
+            {
+                res.send({error: "Could not find survey associated with provided token: " + token});
+            }
+        });
+    });
+}
+ 
+// TODO: May consider abstracting out winner part into own routes.
+ 
+exports.assignWinner = function(req, res ) {
+    var token = req.params.token;
+    console.log(token);
+ 
+    // get surveyId, then votes matching that.
+    db.collection('studies', function(err, studyCollection) {
+        studyCollection.findOne({'token':token}, function(err, study) 
+        {
+            if( study )
+            {
+                db.collection('votes', function(err, voteCollection) {
+                    voteCollection.find({'studyId': study._id }).toArray(function(err, items) 
+                    {
+                        console.log(err);
+ 
+                        var pool = _.uniq(items, function(item,key,a) {
+                                return item.email;
+                            }).filter( function(element, index, array) 
+                            {
+                                try
+                                {
+                                    return element.email && check(element.email).isEmail();
+                                }
+                                catch(ex)
+                                {
+                                    return false;
+                                }
+                            });
+ 
+                        if (pool && pool.length > 0 )
+                        {
+                            // pick random...other fun ways?
+                            var winner = pool[Math.floor(Math.random()*pool.length)];
+                            res.send({'winner': winner.email});
+                        }
+                        else
+                        {
+                            res.send({'winner': 'Error: No valid emails'});
+                        }
+ 
+                    });
+                });
+            }
+        });
+    });
+};
+ 
+// TODO: use token of some sort instead of email.
+exports.notifyParticipant = function(req, res) {
+    var email = req.body.email;
+    var kind = req.body.kind;
+ 
+    var redeem = "The researcher will follow up with more instructions on how to receive your compensation.";
+    if( kind == "AMZN" )
+    {
+        redeem = "Your amazon gift card will be sent directly from amazon.com.";
+    }
+    else if( kind == "SURFACE" )
+    {
+        redeem = "Your Microsoft surface will be sent as soon as you reply back with your shipping address.";
+    }
+    else if( kind == "IPADMINI" )
+    {
+        redeem = "Your iPad Mini will be sent as soon as you reply back with your shipping address.";
+    }
+    else if( kind == "GITHUB" )
+    {
+        redeem = "Your github swag will be sent as soon as you reply back with your shipping address.";
+    }
+    else if( kind == "BROWSERSTACK" )
+    {
+        redeem = "Your browserstack token will be in another email.";
+        // TODO include in ...
+    }
+ 
+    var msg = {
+            text: "Thank you for participating in our research study.\n" +
+                  redeem + "\n"
+            , 
+            from:    "<support@checkbox.io>",
+            to:      "<"+ email +">",
+            //to: "<cscorley@gmail.com>",
+            //cc:      "else <else@gmail.com>",
+            subject: "checkbox.io: study winner"
+        };
+ 
+    emailServer.send(msg, 
+        function(err, message) 
+        { 
+            console.log(err || message);
+            if( err )
+            {
+                res.send( {error: err } );
+            }
+            else
+            {
+                res.send( {message: message} );
+            }
+        }
+    );
+ 
+}
+ 
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/create.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/create.js.html new file mode 100644 index 0000000..eeb1b83 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/create.js.html @@ -0,0 +1,422 @@ + + + + Code coverage report for checkbox_test_generation/mock_routes/create.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_routes/ create.js +

+
+
+ 19.51% + Statements + 8/41 +
+
+ 0% + Branches + 0/14 +
+
+ 0% + Functions + 0/11 +
+
+ 19.51% + Lines + 8/41 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120  + + + +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  + 
//var mongo = require('mongodb');
+var crypto = require('crypto');
+var emailjs = require('emailjs/email');
+var models = require('./studyModel.js');
+ 
+class ObjectID{
+    constructor(val){
+        this.val =  val;
+    }
+}
+ 
+var db = require("../mock_db/db.js");
+ 
+ 
+/*var Server = mongo.Server,
+    Db = mongo.Db,
+    BSON = mongo.BSONPure;
+ 
+var MongoClient = mongo.MongoClient;
+var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+*/
+var emailServer  = emailjs.server.connect({
+   user:    process.env.MAIL_USER, 
+   password:process.env.MAIL_PASSWORD, 
+   host:    process.env.MAIL_SMTP, 
+   ssl:     true,
+ 
+});
+ 
+exports.createStudy = function(req, res) {
+ 
+    var invitecode = req.body.invitecode; 
+    var studyKind = req.body.studyKind;
+ 
+    if( invitecode != "RESEARCH" )
+    {
+        res.send({'error':'Invalid invitecode'});
+        return;
+    }
+ 
+    basicCreate( req, res, studyKind ).onCreate( function(study)
+    {
+    	db.collection('studies', function(err, collection) 
+    	{
+    		if( err )
+    			console.log( err );
+ 
+        	collection.insert(study, {safe:true}, function(err, result) 
+        	{
+        		console.log( err || "Study created: " + study._id );
+ 
+        		if( err )
+        		{
+        			res.send({error: err });
+        		}
+        		else
+        		{
+                    study.setPublicLink( study._id );
+ 
+                    // update with new public link, and notify via email, redirect user to admin page.
+                    collection.update( {'_id' : study._id}, {'$set' : {'publicLink' : study.publicLink}},
+                        function(err, result )
+                    {
+                        sendStudyEmail( study );
+                        res.send({admin_url: study.adminLink});
+                    });
+        		}
+        	});
+ 
+        });
+    });
+};
+ 
+ 
+ 
+function basicCreate(req, res, kind) 
+{
+	console.log( kind );
+    this.onCreate = function ( onReady )
+    {
+	    crypto.randomBytes(48, function(ex, buf) 
+	    {
+	        // alternative: https://github.com/broofa/node-uuid
+	        var token = buf.toString('hex');
+ 
+	        console.log( token );
+ 
+	        var study = null;
+	        if( kind == "survey")
+	        {
+	        	study = new models.SurveyModel( req.body, token );
+	        }
+	        if( kind == "dataStudy")
+	        {
+	        	study = new models.DataStudyModel( req.body, token );
+	        }
+ 
+	        console.log( study );
+ 
+	        onReady(study);
+	    });
+	};
+ 
+	return this;
+}
+ 
+function sendStudyEmail (study) {
+    emailServer.send( study.getMessage(), 
+        function(err, message) 
+        { 
+            console.log(err || message); 
+        }
+    );
+}
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/index.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/index.html new file mode 100644 index 0000000..50cd8ab --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/index.html @@ -0,0 +1,106 @@ + + + + Code coverage report for checkbox_test_generation/mock_routes/ + + + + + + + +
+
+

+ all files checkbox_test_generation/mock_routes/ +

+
+
+ 21.97% + Statements + 29/132 +
+
+ 4% + Branches + 1/25 +
+
+ 2.38% + Functions + 1/42 +
+
+ 22.14% + Lines + 29/131 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
study.js
13.75%11/800%0/210%0/2213.75%11/80
upload.js
34.62%18/5225%1/45%1/2035.29%18/51
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/study.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/study.js.html new file mode 100644 index 0000000..07eddf1 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/study.js.html @@ -0,0 +1,731 @@ + + + + Code coverage report for checkbox_test_generation/mock_routes/study.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_routes/ study.js +

+
+
+ 13.75% + Statements + 11/80 +
+
+ 0% + Branches + 0/21 +
+
+ 0% + Functions + 0/22 +
+
+ 13.75% + Lines + 11/80 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223  +  + + + +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  + 
/*var mongo = require('mongodb');
+*/
+var check = require('validator').check;
+var _ = require('underscore');
+var fileService = require('./upload.js');
+ 
+class ObjectID{
+    constructor(val){
+        this.val =  val;
+    }
+}
+ 
+var db = require("../mock_db/db.js");
+ 
+/*var Server = mongo.Server,
+    Db = mongo.Db,
+    ObjectID = mongo.ObjectID;
+ 
+ 
+var MongoClient = mongo.MongoClient;
+var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+*/
+ 
+ 
+exports.listing = function(req, res)
+{
+    db.collection('votes', function(err, votes) {
+ 
+        db.collection('studies', function(err, studies ) {
+ 
+            studies.find().toArray(
+                function(err, studyItems) 
+                {
+                    console.log(err);
+                    votes.aggregate(
+                    [
+                        { $group: { _id: '$studyId', votes: { $sum: 1 } } }
+                    ], 
+                    function(err, groupResult) 
+                    {
+                        console.log(err + ":" + groupResult);
+ 
+                        var voteMap = {};
+                        var result = {studies:[]};
+                        for( var i = 0; i < groupResult.length; i++ )
+                        {
+                            var g = groupResult[i];
+                            if( g._id != null )
+                            {
+                                voteMap[g._id] = g.votes;
+                            }
+                        }
+ 
+                        console.log( JSON.stringify(voteMap) );
+ 
+                        for( var i = 0; i < studyItems.length; i++ )
+                        {
+                            var s = studyItems[i];
+                            if( voteMap[s._id] )
+                            {
+                                var study = {
+                                    id: s._id, 
+                                    votes: voteMap[s._id],
+                                    name: s.name,
+                                    status: s.status,
+                                    goal: s.goal,
+                                    awards: s.awards,
+                                    studyKind: s.studyKind,
+                                    link: s.publicLink,
+                                    results: s.results,
+                                    description: s.description                                    
+                                };
+ 
+                                if( s.skipListing )
+                                {
+                                    // skip
+                                }
+                                else
+                                {
+                                    result["studies"].push( study );
+                                }
+                            }
+                        }
+ 
+                        statusPriority = 
+                        {
+                            open: 0, awarded: 1, closed: 2
+                        };
+ 
+                        result.studies.sort(function(a,b)
+                        {
+                            var aPriority = statusPriority[a.status];
+                            var bPriority = statusPriority[b.status];
+ 
+                            return aPriority - bPriority;
+                        });
+ 
+                        res.send(result);
+                    });
+                }
+            );
+        });
+    });
+}
+ 
+exports.loadStudy = function(req, res) {
+    var id = req.params.id;
+    console.log('Retrieving study: ' + id);
+    db.collection('studies', function(err, collection) {
+        console.log('inside db');
+        collection.findOne({'_id':new ObjectID(id)}, function(err, item) {
+            // don't allow token to be seen by others.
+            console.log("inside item");
+            console.log(item);
+            delete item["token"];
+            delete item["invitecode"];
+ 
+            res.send(item);
+        });
+    });
+};
+ 
+exports.status = function(req, res) {
+    var studyId = new ObjectID(req.params.id);
+ 
+    db.collection('votes', function(err, collection) {
+        collection.find({'studyId':studyId}).toArray(function(err, items) {            
+            res.send({votes: items.length});
+        });
+    });
+};
+ 
+ 
+exports.voteStatus = function(req, res)
+{
+    var studyId = new ObjectID(req.query.studyId);
+    var ip = getClientAddress(req);
+    var fingerprint = req.query.fingerprint;
+ 
+ 
+    db.collection('votes', function(err, collection) {
+        collection.find(
+        {
+            studyId: studyId,
+            ip: ip,
+            fingerprint: fingerprint
+        }).toArray(
+            function(err, items) 
+            {
+                if( items && items.length > 0 )
+                {
+                    res.send({status:"voted", items: items});
+                }
+                else
+                {
+                    res.send({status:"ok"});
+                }
+            });
+    });
+}
+ 
+exports.submitVote = function(req, res) {
+ 
+    var studyId = req.body.studyId;
+    var ip = getClientAddress(req);
+    var fingerprint = req.body.fingerprint;
+    var answers = JSON.parse(req.body.answers);
+    var email = req.body.email;
+    var contact = req.body.contact;
+ 
+    var vote = 
+    {
+        studyId: new ObjectID(studyId),
+        timestamp: new Date(),
+        ip: ip,
+        fingerprint: fingerprint,
+        answers: answers,
+        email: email,
+        contact: contact
+    };
+ 
+    if( req.files && req.files.files && req.files.files.length > 0 )
+    {
+        fileService.uploadFiles( req, function(results) {
+            console.log( results );
+            vote.files = results;
+            commonSubmit(req,res, vote);
+        });
+    }
+    else
+    {    
+        commonSubmit(req,res, vote);
+    }
+ 
+}
+ 
+function commonSubmit(req, res, vote )
+{
+ 
+    console.log('Adding vote: ' + vote);
+ 
+    db.collection('votes', function(err, collection) {
+        collection.insert(vote, {safe:true}, function(err, result) {
+            if (err) {
+                res.send({'error':'An error has occurred'});
+            } else {
+                console.log('Success: ' + JSON.stringify(result[0]));
+                res.send( {'done':true });
+            }
+        });
+    });
+}
+ 
+var getClientAddress = function (req) {
+    return (req.headers['x-forwarded-for'] || '').split(',')[0] 
+        || req.connection.remoteAddress;
+};
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/studyModel.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/studyModel.js.html new file mode 100644 index 0000000..b410e2b --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/studyModel.js.html @@ -0,0 +1,389 @@ + + + + Code coverage report for checkbox_test_generation/mock_routes/studyModel.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_routes/ studyModel.js +

+
+
+ 29.27% + Statements + 12/41 +
+
+ 0% + Branches + 0/2 +
+
+ 22.22% + Functions + 2/9 +
+
+ 29.27% + Lines + 12/41 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109  +  +  + +  + +  + +  + +  + +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  + + 
// This is a constructor that is used to setup inheritance without
+// invoking the base's constructor. It does nothing, so it doesn't
+// create properties on the prototype like our previous example did
+function surrogateCtor() {}
+ 
+function extend(base, sub) {
+  // Copy the prototype from the base to setup inheritance
+  surrogateCtor.prototype = base.prototype;
+  // Tricky huh?
+  sub.prototype = new surrogateCtor();
+  // Remember the constructor property was set wrong, let's fix it
+  sub.prototype.constructor = sub;
+}
+ 
+StudyBase = function(incoming)
+{
+	var self = this;
+ 
+	self.name = incoming.name;
+    self.description = incoming.description;
+    self.studyKind = incoming.studyKind;
+ 
+    self.researcherName = incoming.researcherName;
+    self.contact = incoming.contact;
+ 
+    self.awards = incoming.awards;
+ 
+    self.awardOptions = ['Amazon Gift Card', 'Github Swag', 'BrowserStack', 'Windows Surface RT', 'iPad Mini', 'Other', 'None'];
+ 
+	self.status = "open";
+	self.goal = incoming.goal || 100;
+ 
+	self.invitecode = incoming.invitecode;
+};
+ 
+SurveyModel = function( incoming, token )
+{
+	var self = this;
+	StudyBase.call(this, incoming);
+ 
+	self.markdown = incoming.markdown;
+	self.token = token;
+ 
+	self.adminLink = "/studies/admin/?token=" + token;
+ 
+	self.setPublicLink = function(id)
+	{
+		self.publicLink = "/studies/?id=" + id;
+	};
+ 
+ 
+	self.getMessage = function()
+	{
+		return {
+	        text: "Your survey has been created.\n" +
+              "Survey admin url:\n" + 
+              self.adminLink + "\n" +
+              "Public survey url: \n" + 
+              self.publicLink + "\n"
+            ,
+            from:    "Chris Parnin <support@checkbox.io>",
+            to:      self.researcherName + "<"+ self.contact +">",
+            subject: "checkbox.io: survey created"
+        };
+	};
+}
+ 
+extend(StudyBase, SurveyModel);
+//SurveyModel.prototype = new StudyBase();
+//SurveyModel.prototype.constructor = SurveyModel;
+exports.SurveyModel = SurveyModel;
+ 
+DataStudyModel = function( incoming, token )
+{
+	var self = this;
+	StudyBase.call(this, incoming);
+ 
+	self.markdown = incoming.markdown;
+	self.token = token;
+ 
+	self.adminLink = "/studies/admin/?token=" + token;
+ 
+	self.setPublicLink = function(id)
+	{
+		self.publicLink = "/studies/?id=" + id;
+	};
+ 
+ 
+	self.getMessage = function()
+	{
+		return {
+	        text: "Your data study has been created.\n" +
+              "Study admin url:\n" + 
+              self.adminLink + "\n" +
+              "Public data study url: \n" + 
+              self.publicLink + "\n"
+            ,
+            from:    "Chris Parnin <support@checkbox.io>",
+            to:      self.researcherName + "<"+ self.contact +">",
+            subject: "checkbox.io: data study created"
+        };
+	};
+}
+ 
+extend(StudyBase, DataStudyModel);
+//DataStudyModel.prototype = new StudyBase();
+//DataStudyModel.prototype.constructor = DataStudyModel;
+exports.DataStudyModel = DataStudyModel;
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/upload.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/upload.js.html new file mode 100644 index 0000000..80303d9 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/mock_routes/upload.js.html @@ -0,0 +1,437 @@ + + + + Code coverage report for checkbox_test_generation/mock_routes/upload.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/mock_routes/ upload.js +

+
+
+ 34.62% + Statements + 18/52 +
+
+ 25% + Branches + 1/4 +
+
+ 5% + Functions + 1/20 +
+
+ 35.29% + Lines + 18/51 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 + + +  + + + +  + +  +  + +  +  +  + + + +  + + +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
var express = require('express');
+var fs = require("fs");
+var async = require("async");
+ 
+var mongo = require('mongodb');
+var check = require('validator').check;
+var _ = require('underscore');
+ 
+var archiver = require('archiver');
+ 
+ 
+var Server = mongo.Server,
+    Db = mongo.Db,
+    ObjectID = mongo.ObjectID;
+ 
+var MongoClient = mongo.MongoClient;
+var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+ 
+exports.uploadFiles = function(req, onReady)
+{
+	var files = req.files.files;
+ 
+	async.map( files, uploadFile, function(err, results)
+	{
+		onReady( results );
+	});
+};
+ 
+exports.readFiles = function(res, fileIds, onReady)
+{
+    var archive = archiver('zip');
+ 
+    archive.on('error', function(err) {
+  		throw err;
+	});
+ 
+    archive.pipe( res );
+ 
+	async.map( fileIds.map(function(elem){ return {fileId:elem,archive:archive} }), readFileStream, function(err, results) 
+	{
+	 	onReady(err, archive);
+	});
+}
+ 
+function readFileStream(obj, onReady)
+{
+	var fileId = obj.fileId;
+	var archive = obj.archive;
+ 
+	new mongo.GridStore(db, fileId, "r").open(function(err, gridStore)
+    {
+		var stream = gridStore.stream(true);
+		//console.log("streaming: " + fileId );
+ 
+        stream.on("data", function(item) {
+            // Destroy the stream
+        	//stream.destroy();
+        	//console.log("data: " + fileId);
+        });
+ 
+        stream.on("end", function(item) {
+        	//console.log("Stream end: " + fileId);
+        });
+ 
+        stream.on("close", function() {
+        	//console.log("Stream closed: " + fileId);
+        });
+ 
+	 	archive.append( stream, { name: fileId + "-" + gridStore.filename }, function()
+ 	 	{
+ 	 		console.log("appended: " + gridStore.filename);
+ 	 	});
+ 
+		onReady(err, fileId);
+	});
+}
+ 
+function readFile(fileId, onReady)
+{
+	// Read back all the written content and verify the correctness
+	mongo.GridStore.read(db, fileId, function(err, fileData) 
+	{
+		console.log( fileData.length );
+		onReady(err, {fileId:fileId, data: fileData});
+	});
+}
+ 
+function uploadFile(file, onReady)
+{
+ 
+	var fileId = new ObjectID();
+ 
+	var gs = new mongo.GridStore(db, fileId, file.name, "w", {
+	    "content_type": file.type,
+	    "chunk_size": 1024*8
+	});
+ 
+	gs.open(function(err, gs)
+	{
+		gs.writeFile(file.path, function(err, a) 
+		{
+			console.log(err + ": wrote file");
+ 
+			gs.close(function(err,result)
+			{
+				// Read back all the written content and verify the correctness
+				mongo.GridStore.read(db, fileId, function(err, fileData) {
+					console.log(err);
+					if( fileData )
+						console.log(fileData.length);
+ 
+					onReady(err, {fileId:fileId});
+				});
+			});
+ 
+		});
+	});
+ 
+}
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/create.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/create.js.html new file mode 100644 index 0000000..8a99f93 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/create.js.html @@ -0,0 +1,398 @@ + + + + Code coverage report for checkbox_test_generation/routes/create.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/routes/ create.js +

+
+
+ 30.43% + Statements + 14/46 +
+
+ 6.25% + Branches + 1/16 +
+
+ 9.09% + Functions + 1/11 +
+
+ 30.43% + Lines + 14/46 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 + + + +  +  + +  +  +  + + + +  + + +  +  + +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  + 
var mongo = require('mongodb');
+var crypto = require('crypto');
+var emailjs = require('emailjs/email');
+var models = require('./studyModel.js');
+ 
+ 
+var Server = mongo.Server,
+    Db = mongo.Db,
+    BSON = mongo.BSONPure;
+ 
+var MongoClient = mongo.MongoClient;
+var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+ 
+var emailServer  = emailjs.server.connect({
+   user:    process.env.MAIL_USER, 
+   password:process.env.MAIL_PASSWORD, 
+   host:    process.env.MAIL_SMTP, 
+   ssl:     true,
+ 
+});
+ 
+exports.createStudy = function(req, res) {
+ 
+    var invitecode = req.body.invitecode; 
+    var studyKind = req.body.studyKind;
+ 
+    if( invitecode != "RESEARCH" )
+    {
+        res.send({'error':'Invalid invitecode'});
+        return;
+    }
+ 
+    basicCreate( req, res, studyKind ).onCreate( function(study)
+    {
+    	db.collection('studies', function(err, collection) 
+    	{
+    		if( err )
+    			console.log( err );
+ 
+        	collection.insert(study, {safe:true}, function(err, result) 
+        	{
+        		console.log( err || "Study created: " + study._id );
+ 
+        		if( err )
+        		{
+        			res.send({error: err });
+        		}
+        		else
+        		{
+                    study.setPublicLink( study._id );
+ 
+                    // update with new public link, and notify via email, redirect user to admin page.
+                    collection.update( {'_id' : study._id}, {'$set' : {'publicLink' : study.publicLink}},
+                        function(err, result )
+                    {
+                        sendStudyEmail( study );
+                        res.send({admin_url: study.adminLink});
+                    });
+        		}
+        	});
+ 
+        });
+    });
+};
+ 
+ 
+ 
+function basicCreate(req, res, kind) 
+{
+	console.log( kind );
+    this.onCreate = function ( onReady )
+    {
+	    crypto.randomBytes(48, function(ex, buf) 
+	    {
+	        // alternative: https://github.com/broofa/node-uuid
+	        var token = buf.toString('hex');
+ 
+	        console.log( token );
+ 
+	        var study = null;
+	        if( kind == "survey")
+	        {
+	        	study = new models.SurveyModel( req.body, token );
+	        }
+	        if( kind == "dataStudy")
+	        {
+	        	study = new models.DataStudyModel( req.body, token );
+	        }
+ 
+	        console.log( study );
+ 
+	        onReady(study);
+	    });
+	};
+ 
+	return this;
+}
+ 
+function sendStudyEmail (study) {
+    emailServer.send( study.getMessage(), 
+        function(err, message) 
+        { 
+            console.log(err || message); 
+        }
+    );
+}
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/index.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/index.html new file mode 100644 index 0000000..9d70a4f --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/index.html @@ -0,0 +1,106 @@ + + + + Code coverage report for checkbox_test_generation/routes/ + + + + + + + +
+
+

+ all files checkbox_test_generation/routes/ +

+
+
+ 26.12% + Statements + 35/134 +
+
+ 7.41% + Branches + 2/27 +
+
+ 4.76% + Functions + 2/42 +
+
+ 26.32% + Lines + 35/133 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
study.js
20.73%17/824.35%1/234.55%1/2220.73%17/82
upload.js
34.62%18/5225%1/45%1/2035.29%18/51
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/study.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/study.js.html new file mode 100644 index 0000000..d48564f --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/study.js.html @@ -0,0 +1,689 @@ + + + + Code coverage report for checkbox_test_generation/routes/study.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/routes/ study.js +

+
+
+ 20.73% + Statements + 17/82 +
+
+ 4.35% + Branches + 1/23 +
+
+ 4.55% + Functions + 1/22 +
+
+ 20.73% + Lines + 17/82 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 + + + +  + +  +  +  +  + + + +  + + +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  + 
var mongo = require('mongodb');
+var check = require('validator').check;
+var _ = require('underscore');
+var fileService = require('./upload.js');
+ 
+var Server = mongo.Server,
+    Db = mongo.Db,
+    ObjectID = mongo.ObjectID;
+ 
+ 
+var MongoClient = mongo.MongoClient;
+var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+ 
+exports.listing = function(req, res)
+{
+    db.collection('votes', function(err, votes) {
+ 
+        db.collection('studies', function(err, studies ) {
+ 
+            studies.find().toArray(
+                function(err, studyItems) 
+                {
+                    console.log(err);
+                    votes.aggregate(
+                    [
+                        { $group: { _id: '$studyId', votes: { $sum: 1 } } }
+                    ], 
+                    function(err, groupResult) 
+                    {
+                        console.log(err + ":" + groupResult);
+ 
+                        var voteMap = {};
+                        var result = {studies:[]};
+                        for( var i = 0; i < groupResult.length; i++ )
+                        {
+                            var g = groupResult[i];
+                            if( g._id != null )
+                            {
+                                voteMap[g._id] = g.votes;
+                            }
+                        }
+ 
+                        console.log( JSON.stringify(voteMap) );
+ 
+                        for( var i = 0; i < studyItems.length; i++ )
+                        {
+                            var s = studyItems[i];
+                            if( voteMap[s._id] )
+                            {
+                                var study = {
+                                    id: s._id, 
+                                    votes: voteMap[s._id],
+                                    name: s.name,
+                                    status: s.status,
+                                    goal: s.goal,
+                                    awards: s.awards,
+                                    studyKind: s.studyKind,
+                                    link: s.publicLink,
+                                    results: s.results,
+                                    description: s.description                                    
+                                };
+ 
+                                if( s.skipListing )
+                                {
+                                    // skip
+                                }
+                                else
+                                {
+                                    result["studies"].push( study );
+                                }
+                            }
+                        }
+ 
+                        statusPriority = 
+                        {
+                            open: 0, awarded: 1, closed: 2
+                        };
+ 
+                        result.studies.sort(function(a,b)
+                        {
+                            var aPriority = statusPriority[a.status];
+                            var bPriority = statusPriority[b.status];
+ 
+                            return aPriority - bPriority;
+                        });
+ 
+                        res.send(result);
+                    });
+                }
+            );
+        });
+    });
+}
+ 
+exports.loadStudy = function(req, res) {
+    var id = req.params.id;
+    console.log('Retrieving study: ' + id);
+    db.collection('studies', function(err, collection) {
+        collection.findOne({'_id':new ObjectID(id)}, function(err, item) {
+            // don't allow token to be seen by others.
+            delete item["token"];
+            delete item["invitecode"];
+ 
+            res.send(item);
+        });
+    });
+};
+ 
+exports.status = function(req, res) {
+    var studyId = new ObjectID(req.params.id);
+ 
+    db.collection('votes', function(err, collection) {
+        collection.find({'studyId':studyId}).toArray(function(err, items) {            
+            res.send({votes: items.length});
+        });
+    });
+};
+ 
+ 
+exports.voteStatus = function(req, res)
+{
+    var studyId = new ObjectID(req.query.studyId);
+    var ip = getClientAddress(req);
+    var fingerprint = req.query.fingerprint;
+ 
+ 
+    db.collection('votes', function(err, collection) {
+        collection.find(
+        {
+            studyId: studyId,
+            ip: ip,
+            fingerprint: fingerprint
+        }).toArray(
+            function(err, items) 
+            {
+                if( items && items.length > 0 )
+                {
+                    res.send({status:"voted", items: items});
+                }
+                else
+                {
+                    res.send({status:"ok"});
+                }
+            });
+    });
+}
+ 
+exports.submitVote = function(req, res) {
+ 
+    var studyId = req.body.studyId;
+    var ip = getClientAddress(req);
+    var fingerprint = req.body.fingerprint;
+    var answers = JSON.parse(req.body.answers);
+    var email = req.body.email;
+    var contact = req.body.contact;
+ 
+    var vote = 
+    {
+        studyId: new ObjectID(studyId),
+        timestamp: new Date(),
+        ip: ip,
+        fingerprint: fingerprint,
+        answers: answers,
+        email: email,
+        contact: contact
+    };
+ 
+    if( req.files && req.files.files && req.files.files.length > 0 )
+    {
+        fileService.uploadFiles( req, function(results) {
+            console.log( results );
+            vote.files = results;
+            commonSubmit(req,res, vote);
+        });
+    }
+    else
+    {    
+        commonSubmit(req,res, vote);
+    }
+ 
+}
+ 
+function commonSubmit(req, res, vote )
+{
+ 
+    console.log('Adding vote: ' + vote);
+ 
+    db.collection('votes', function(err, collection) {
+        collection.insert(vote, {safe:true}, function(err, result) {
+            if (err) {
+                res.send({'error':'An error has occurred'});
+            } else {
+                console.log('Success: ' + JSON.stringify(result[0]));
+                res.send( {'done':true });
+            }
+        });
+    });
+}
+ 
+var getClientAddress = function (req) {
+    return (req.headers['x-forwarded-for'] || '').split(',')[0] 
+        || req.connection.remoteAddress;
+};
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/studyModel.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/studyModel.js.html new file mode 100644 index 0000000..2792a21 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/studyModel.js.html @@ -0,0 +1,389 @@ + + + + Code coverage report for checkbox_test_generation/routes/studyModel.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/routes/ studyModel.js +

+
+
+ 29.27% + Statements + 12/41 +
+
+ 0% + Branches + 0/2 +
+
+ 22.22% + Functions + 2/9 +
+
+ 29.27% + Lines + 12/41 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109  +  +  + +  + +  + +  + +  + +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  + + 
// This is a constructor that is used to setup inheritance without
+// invoking the base's constructor. It does nothing, so it doesn't
+// create properties on the prototype like our previous example did
+function surrogateCtor() {}
+ 
+function extend(base, sub) {
+  // Copy the prototype from the base to setup inheritance
+  surrogateCtor.prototype = base.prototype;
+  // Tricky huh?
+  sub.prototype = new surrogateCtor();
+  // Remember the constructor property was set wrong, let's fix it
+  sub.prototype.constructor = sub;
+}
+ 
+StudyBase = function(incoming)
+{
+	var self = this;
+ 
+	self.name = incoming.name;
+    self.description = incoming.description;
+    self.studyKind = incoming.studyKind;
+ 
+    self.researcherName = incoming.researcherName;
+    self.contact = incoming.contact;
+ 
+    self.awards = incoming.awards;
+ 
+    self.awardOptions = ['Amazon Gift Card', 'Github Swag', 'BrowserStack', 'Windows Surface RT', 'iPad Mini', 'Other', 'None'];
+ 
+	self.status = "open";
+	self.goal = incoming.goal || 100;
+ 
+	self.invitecode = incoming.invitecode;
+};
+ 
+SurveyModel = function( incoming, token )
+{
+	var self = this;
+	StudyBase.call(this, incoming);
+ 
+	self.markdown = incoming.markdown;
+	self.token = token;
+ 
+	self.adminLink = "/studies/admin/?token=" + token;
+ 
+	self.setPublicLink = function(id)
+	{
+		self.publicLink = "/studies/?id=" + id;
+	};
+ 
+ 
+	self.getMessage = function()
+	{
+		return {
+	        text: "Your survey has been created.\n" +
+              "Survey admin url:\n" + 
+              self.adminLink + "\n" +
+              "Public survey url: \n" + 
+              self.publicLink + "\n"
+            ,
+            from:    "Chris Parnin <support@checkbox.io>",
+            to:      self.researcherName + "<"+ self.contact +">",
+            subject: "checkbox.io: survey created"
+        };
+	};
+}
+ 
+extend(StudyBase, SurveyModel);
+//SurveyModel.prototype = new StudyBase();
+//SurveyModel.prototype.constructor = SurveyModel;
+exports.SurveyModel = SurveyModel;
+ 
+DataStudyModel = function( incoming, token )
+{
+	var self = this;
+	StudyBase.call(this, incoming);
+ 
+	self.markdown = incoming.markdown;
+	self.token = token;
+ 
+	self.adminLink = "/studies/admin/?token=" + token;
+ 
+	self.setPublicLink = function(id)
+	{
+		self.publicLink = "/studies/?id=" + id;
+	};
+ 
+ 
+	self.getMessage = function()
+	{
+		return {
+	        text: "Your data study has been created.\n" +
+              "Study admin url:\n" + 
+              self.adminLink + "\n" +
+              "Public data study url: \n" + 
+              self.publicLink + "\n"
+            ,
+            from:    "Chris Parnin <support@checkbox.io>",
+            to:      self.researcherName + "<"+ self.contact +">",
+            subject: "checkbox.io: data study created"
+        };
+	};
+}
+ 
+extend(StudyBase, DataStudyModel);
+//DataStudyModel.prototype = new StudyBase();
+//DataStudyModel.prototype.constructor = DataStudyModel;
+exports.DataStudyModel = DataStudyModel;
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/upload.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/upload.js.html new file mode 100644 index 0000000..e04480c --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/routes/upload.js.html @@ -0,0 +1,437 @@ + + + + Code coverage report for checkbox_test_generation/routes/upload.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/routes/ upload.js +

+
+
+ 34.62% + Statements + 18/52 +
+
+ 25% + Branches + 1/4 +
+
+ 5% + Functions + 1/20 +
+
+ 35.29% + Lines + 18/51 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 + + +  + + + +  + +  +  + +  +  +  + + + +  + + +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
var express = require('express');
+var fs = require("fs");
+var async = require("async");
+ 
+var mongo = require('mongodb');
+var check = require('validator').check;
+var _ = require('underscore');
+ 
+var archiver = require('archiver');
+ 
+ 
+var Server = mongo.Server,
+    Db = mongo.Db,
+    ObjectID = mongo.ObjectID;
+ 
+var MongoClient = mongo.MongoClient;
+var db = null;
+MongoClient.connect("mongodb://"+process.env.MONGO_USER+":"+process.env.MONGO_PASSWORD+"@"+process.env.MONGO_IP+":27017/site?authSource=admin", function(err, authdb) {
+  // Now you can use the database in the db variable
+  db = authdb;
+  console.log( err || "connected!" );
+});
+ 
+exports.uploadFiles = function(req, onReady)
+{
+	var files = req.files.files;
+ 
+	async.map( files, uploadFile, function(err, results)
+	{
+		onReady( results );
+	});
+};
+ 
+exports.readFiles = function(res, fileIds, onReady)
+{
+    var archive = archiver('zip');
+ 
+    archive.on('error', function(err) {
+  		throw err;
+	});
+ 
+    archive.pipe( res );
+ 
+	async.map( fileIds.map(function(elem){ return {fileId:elem,archive:archive} }), readFileStream, function(err, results) 
+	{
+	 	onReady(err, archive);
+	});
+}
+ 
+function readFileStream(obj, onReady)
+{
+	var fileId = obj.fileId;
+	var archive = obj.archive;
+ 
+	new mongo.GridStore(db, fileId, "r").open(function(err, gridStore)
+    {
+		var stream = gridStore.stream(true);
+		//console.log("streaming: " + fileId );
+ 
+        stream.on("data", function(item) {
+            // Destroy the stream
+        	//stream.destroy();
+        	//console.log("data: " + fileId);
+        });
+ 
+        stream.on("end", function(item) {
+        	//console.log("Stream end: " + fileId);
+        });
+ 
+        stream.on("close", function() {
+        	//console.log("Stream closed: " + fileId);
+        });
+ 
+	 	archive.append( stream, { name: fileId + "-" + gridStore.filename }, function()
+ 	 	{
+ 	 		console.log("appended: " + gridStore.filename);
+ 	 	});
+ 
+		onReady(err, fileId);
+	});
+}
+ 
+function readFile(fileId, onReady)
+{
+	// Read back all the written content and verify the correctness
+	mongo.GridStore.read(db, fileId, function(err, fileData) 
+	{
+		console.log( fileData.length );
+		onReady(err, {fileId:fileId, data: fileData});
+	});
+}
+ 
+function uploadFile(file, onReady)
+{
+ 
+	var fileId = new ObjectID();
+ 
+	var gs = new mongo.GridStore(db, fileId, file.name, "w", {
+	    "content_type": file.type,
+	    "chunk_size": 1024*8
+	});
+ 
+	gs.open(function(err, gs)
+	{
+		gs.writeFile(file.path, function(err, a) 
+		{
+			console.log(err + ": wrote file");
+ 
+			gs.close(function(err,result)
+			{
+				// Read back all the written content and verify the correctness
+				mongo.GridStore.read(db, fileId, function(err, fileData) {
+					console.log(err);
+					if( fileData )
+						console.log(fileData.length);
+ 
+					onReady(err, {fileId:fileId});
+				});
+			});
+ 
+		});
+	});
+ 
+}
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/server.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/server.js.html new file mode 100644 index 0000000..340081c --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/server.js.html @@ -0,0 +1,350 @@ + + + + Code coverage report for checkbox_test_generation/server.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/ server.js +

+
+
+ 80.77% + Statements + 21/26 +
+
+ 100% + Branches + 0/0 +
+
+ 33.33% + Functions + 1/3 +
+
+ 80.77% + Lines + 21/26 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  + + + +  +  + + +  +  +  +  +  +  + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + + +  + +  + + +  +  + + + +  + + + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + 
var express = require('express'),
+cors = require('cors'),
+//marqdown = require('./marqdown.js'),
+//routes = require('./routes/designer.js'),
+//votes = require('./routes/live.js'),
+//upload = require('./routes/upload.js'),
+/*create = require('./routes/create.js'),
+study = require('./routes/study.js'),
+admin = require('./routes/admin.js');
+*/
+ 
+create = require('./mock_routes/create.js'),
+study = require('./mock_routes/study.js'),
+admin = require('./mock_routes/admin.js');
+ 
+ 
+var app = express();
+ 
+app.configure(function () {
+app.use(express.logger('dev'));     /* 'default', 'short', 'tiny', 'dev' */
+app.use(express.bodyParser());
+});
+ 
+var whitelist = ['http://chrisparnin.me', 'http://pythontutor.com', 'http://happyface.io', 'http://happyface.io:8003', 'http://happyface.io/hf.html'];
+var corsOptions = {
+origin: function(origin, callback){
+var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
+callback(null, originIsWhitelisted);
+}
+};
+ 
+app.options('/api/study/vote/submit/', cors(corsOptions));
+ 
+app.post('/api/design/survey', 
+function(req,res)
+{
+console.log(req.body.markdown);
+//var text = marqdown.render( req.query.markdown );
+var text = marqdown.render( req.body.markdown );
+res.send( {preview: text} );
+}
+);
+ 
+//app.get('/api/design/survey/all', routes.findAll );
+//app.get('/api/design/survey/:id', routes.findById );
+//app.get('/api/design/survey/admin/:token', routes.findByToken );
+ 
+//app.post('/api/design/survey/save', routes.saveSurvey );
+//app.post('/api/design/survey/open/', routes.openSurvey );
+//app.post('/api/design/survey/close/', routes.closeSurvey );
+//app.post('/api/design/survey/notify/', routes.notifyParticipant );
+ 
+ 
+//// ################################
+//// Towards general study management.
+app.get('/api/study/load/:id', study.loadStudy );
+app.get('/api/study/vote/status', study.voteStatus );
+app.get('/api/study/status/:id', study.status );
+ 
+app.get('/api/study/listing', study.listing );
+ 
+app.post('/api/study/create', create.createStudy );
+app.post('/api/study/vote/submit/', cors(corsOptions), study.submitVote );
+ 
+//// ADMIN ROUTES
+app.get('/api/study/admin/:token', admin.loadStudy );
+app.get('/api/study/admin/download/:token', admin.download );
+app.get('/api/study/admin/assign/:token', admin.assignWinner);
+ 
+app.post('/api/study/admin/open/', admin.openStudy );
+app.post('/api/study/admin/close/', admin.closeStudy );
+app.post('/api/study/admin/notify/', admin.notifyParticipant);
+ 
+//// ################################
+ 
+//app.post('/api/upload', upload.uploadFile );
+ 
+// survey listing for studies.
+//app.get('/api/design/survey/all/listing', routes.studyListing );
+ 
+// Download
+//app.get('/api/design/survey/vote/download/:token', votes.download );
+// Winner
+//app.get('/api/design/survey/winner/:token', votes.pickParticipant );
+ 
+// Voting
+//app.get('/api/design/survey/vote/all', votes.findAll );
+//app.post('/api/design/survey/vote/cast', votes.castVote );
+//app.get('/api/design/survey/vote/status', votes.status );
+//app.get('/api/design/survey/vote/stat/:id', votes.getSurveyStats );
+ 
+ 
+ 
+// app.listen(process.env.MONGO_PORT);
+// console.log('Listening on port 3002...');
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/test.js.html b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/test.js.html new file mode 100644 index 0000000..1a839bb --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/checkbox_test_generation/test.js.html @@ -0,0 +1,131 @@ + + + + Code coverage report for checkbox_test_generation/test.js + + + + + + + +
+
+

+ all files / checkbox_test_generation/ test.js +

+
+
+ 100% + Statements + 7/7 +
+
+ 100% + Branches + 0/0 +
+
+ 100% + Functions + 1/1 +
+
+ 100% + Lines + 6/6 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 + + + + +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  + 
require('/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_routes/study.js');
+var request = require("request");
+var assert = require('assert');
+var sinon = require('sinon')
+var mongoose = require('mongoose')
+//require('sinon-mongoose');
+//var nock = require("nock"); 
+ 
+ 
+// request({ url : 'localhost:3002/api/design/survey', method: 'POST'}, function(error, response, body) { console.log(body);} ); 
+request({ url : 'localhost:3002/api/study/load/:id', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/vote/status', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/status/:id', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/listing', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/create', method: 'POST'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/vote/submit/', method: 'POST'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/admin/:token', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/admin/download/:token', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/admin/assign/:token', method: 'GET'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/admin/open/', method: 'POST'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/admin/close/', method: 'POST'}, function(error, response, body) { console.log(body);} ); 
+// request({ url : 'localhost:3002/api/study/admin/notify/', method: 'POST'}, function(error, response, body) { console.log(body);} ); 
+ 
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/index.html b/checkbox_test_generation/coverage/lcov-report/index.html new file mode 100644 index 0000000..16c4626 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/index.html @@ -0,0 +1,119 @@ + + + + Code coverage report for All files + + + + + + + +
+
+

+ / +

+
+
+ 30.11% + Statements + 53/176 +
+
+ 3.03% + Branches + 1/33 +
+
+ 4.35% + Functions + 2/46 +
+
+ 29.89% + Lines + 52/174 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
checkbox_test_generation/
100%7/7100%0/0100%1/1100%6/6
checkbox_test_generation/mock_db/
45.95%17/370%0/80%0/345.95%17/37
checkbox_test_generation/mock_routes/
21.97%29/1324%1/252.38%1/4222.14%29/131
+
+
+ + + + + + + diff --git a/checkbox_test_generation/coverage/lcov-report/prettify.css b/checkbox_test_generation/coverage/lcov-report/prettify.css new file mode 100644 index 0000000..b317a7c --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/prettify.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/checkbox_test_generation/coverage/lcov-report/prettify.js b/checkbox_test_generation/coverage/lcov-report/prettify.js new file mode 100644 index 0000000..ef51e03 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov-report/prettify.js @@ -0,0 +1 @@ +window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/checkbox_test_generation/coverage/lcov-report/sort-arrow-sprite.png b/checkbox_test_generation/coverage/lcov-report/sort-arrow-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..03f704a609c6fd0dbfdac63466a7d7c958b5cbf3 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jii$m5978H@?Fn+^JD|Y9yzj{W`447Gxa{7*dM7nnnD-Lb z6^}Hx2)'; + } + } + return cols; + } + // attaches a data attribute to every tr element with an object + // of data values keyed by column name + function loadRowData(tableRow) { + var tableCols = tableRow.querySelectorAll('td'), + colNode, + col, + data = {}, + i, + val; + for (i = 0; i < tableCols.length; i += 1) { + colNode = tableCols[i]; + col = cols[i]; + val = colNode.getAttribute('data-value'); + if (col.type === 'number') { + val = Number(val); + } + data[col.key] = val; + } + return data; + } + // loads all row data + function loadData() { + var rows = getTableBody().querySelectorAll('tr'), + i; + + for (i = 0; i < rows.length; i += 1) { + rows[i].data = loadRowData(rows[i]); + } + } + // sorts the table using the data for the ith column + function sortByIndex(index, desc) { + var key = cols[index].key, + sorter = function (a, b) { + a = a.data[key]; + b = b.data[key]; + return a < b ? -1 : a > b ? 1 : 0; + }, + finalSorter = sorter, + tableBody = document.querySelector('.coverage-summary tbody'), + rowNodes = tableBody.querySelectorAll('tr'), + rows = [], + i; + + if (desc) { + finalSorter = function (a, b) { + return -1 * sorter(a, b); + }; + } + + for (i = 0; i < rowNodes.length; i += 1) { + rows.push(rowNodes[i]); + tableBody.removeChild(rowNodes[i]); + } + + rows.sort(finalSorter); + + for (i = 0; i < rows.length; i += 1) { + tableBody.appendChild(rows[i]); + } + } + // removes sort indicators for current column being sorted + function removeSortIndicators() { + var col = getNthColumn(currentSort.index), + cls = col.className; + + cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); + col.className = cls; + } + // adds sort indicators for current column being sorted + function addSortIndicators() { + getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; + } + // adds event listeners for all sorter widgets + function enableUI() { + var i, + el, + ithSorter = function ithSorter(i) { + var col = cols[i]; + + return function () { + var desc = col.defaultDescSort; + + if (currentSort.index === i) { + desc = !currentSort.desc; + } + sortByIndex(i, desc); + removeSortIndicators(); + currentSort.index = i; + currentSort.desc = desc; + addSortIndicators(); + }; + }; + for (i =0 ; i < cols.length; i += 1) { + if (cols[i].sortable) { + // add the click event handler on the th so users + // dont have to click on those tiny arrows + el = getNthColumn(i).querySelector('.sorter').parentElement; + if (el.addEventListener) { + el.addEventListener('click', ithSorter(i)); + } else { + el.attachEvent('onclick', ithSorter(i)); + } + } + } + } + // adds sorting functionality to the UI + return function () { + if (!getTable()) { + return; + } + cols = loadColumns(); + loadData(cols); + addSortIndicators(); + enableUI(); + }; +})(); + +window.addEventListener('load', addSorting); diff --git a/checkbox_test_generation/coverage/lcov.info b/checkbox_test_generation/coverage/lcov.info new file mode 100644 index 0000000..ba82b17 --- /dev/null +++ b/checkbox_test_generation/coverage/lcov.info @@ -0,0 +1,353 @@ +TN: +SF:/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/test.js +FN:11,(anonymous_1) +FNF:1 +FNH:1 +FNDA:1,(anonymous_1) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:11,1 +LF:6 +LH:6 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_routes/study.js +FN:8,(anonymous_1) +FN:30,(anonymous_2) +FN:32,(anonymous_3) +FN:34,(anonymous_4) +FN:37,(anonymous_5) +FN:44,(anonymous_6) +FN:95,(anonymous_7) +FN:111,(anonymous_8) +FN:114,(anonymous_9) +FN:116,(anonymous_10) +FN:128,(anonymous_11) +FN:131,(anonymous_12) +FN:132,(anonymous_13) +FN:139,(anonymous_14) +FN:146,(anonymous_15) +FN:153,(anonymous_16) +FN:167,(anonymous_17) +FN:189,(anonymous_18) +FN:202,commonSubmit +FN:207,(anonymous_20) +FN:208,(anonymous_21) +FN:219,(anonymous_22) +FNF:22 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +FNDA:0,(anonymous_12) +FNDA:0,(anonymous_13) +FNDA:0,(anonymous_14) +FNDA:0,(anonymous_15) +FNDA:0,(anonymous_16) +FNDA:0,(anonymous_17) +FNDA:0,(anonymous_18) +FNDA:0,commonSubmit +FNDA:0,(anonymous_20) +FNDA:0,(anonymous_21) +FNDA:0,(anonymous_22) +DA:3,1 +DA:4,1 +DA:5,1 +DA:9,0 +DA:13,1 +DA:30,1 +DA:32,0 +DA:34,0 +DA:36,0 +DA:39,0 +DA:40,0 +DA:46,0 +DA:48,0 +DA:49,0 +DA:50,0 +DA:52,0 +DA:53,0 +DA:55,0 +DA:59,0 +DA:61,0 +DA:63,0 +DA:64,0 +DA:66,0 +DA:79,0 +DA:85,0 +DA:90,0 +DA:95,0 +DA:97,0 +DA:98,0 +DA:100,0 +DA:103,0 +DA:111,1 +DA:112,0 +DA:113,0 +DA:114,0 +DA:115,0 +DA:116,0 +DA:118,0 +DA:119,0 +DA:120,0 +DA:121,0 +DA:123,0 +DA:128,1 +DA:129,0 +DA:131,0 +DA:132,0 +DA:133,0 +DA:139,1 +DA:141,0 +DA:142,0 +DA:143,0 +DA:146,0 +DA:147,0 +DA:155,0 +DA:157,0 +DA:161,0 +DA:167,1 +DA:169,0 +DA:170,0 +DA:171,0 +DA:172,0 +DA:173,0 +DA:174,0 +DA:176,0 +DA:187,0 +DA:189,0 +DA:190,0 +DA:191,0 +DA:192,0 +DA:197,0 +DA:202,1 +DA:205,0 +DA:207,0 +DA:208,0 +DA:209,0 +DA:210,0 +DA:212,0 +DA:213,0 +DA:219,1 +DA:220,0 +LF:80 +LH:11 +BRDA:53,1,0,0 +BRDA:53,1,1,0 +BRDA:64,2,0,0 +BRDA:64,2,1,0 +BRDA:79,3,0,0 +BRDA:79,3,1,0 +BRDA:155,4,0,0 +BRDA:155,4,1,0 +BRDA:155,5,0,0 +BRDA:155,5,1,0 +BRDA:187,6,0,0 +BRDA:187,6,1,0 +BRDA:187,7,0,0 +BRDA:187,7,1,0 +BRDA:187,7,2,0 +BRDA:209,8,0,0 +BRDA:209,8,1,0 +BRDA:220,9,0,0 +BRDA:220,9,1,0 +BRDA:220,10,0,0 +BRDA:220,10,1,0 +BRF:21 +BRH:0 +end_of_record +TN: +SF:/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_routes/upload.js +FN:18,(anonymous_1) +FN:24,(anonymous_2) +FN:28,(anonymous_3) +FN:34,(anonymous_4) +FN:38,(anonymous_5) +FN:44,(anonymous_6) +FN:44,(anonymous_7) +FN:50,readFileStream +FN:55,(anonymous_9) +FN:60,(anonymous_10) +FN:66,(anonymous_11) +FN:70,(anonymous_12) +FN:74,(anonymous_13) +FN:83,readFile +FN:86,(anonymous_15) +FN:93,uploadFile +FN:103,(anonymous_17) +FN:105,(anonymous_18) +FN:109,(anonymous_19) +FN:112,(anonymous_20) +FNF:20 +FNH:1 +FNDA:1,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,readFileStream +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +FNDA:0,(anonymous_12) +FNDA:0,(anonymous_13) +FNDA:0,readFile +FNDA:0,(anonymous_15) +FNDA:0,uploadFile +FNDA:0,(anonymous_17) +FNDA:0,(anonymous_18) +FNDA:0,(anonymous_19) +FNDA:0,(anonymous_20) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:6,1 +DA:7,1 +DA:9,1 +DA:12,1 +DA:16,1 +DA:17,1 +DA:18,1 +DA:20,1 +DA:21,1 +DA:24,1 +DA:26,0 +DA:28,0 +DA:30,0 +DA:34,1 +DA:36,0 +DA:38,0 +DA:39,0 +DA:42,0 +DA:44,0 +DA:46,0 +DA:50,1 +DA:52,0 +DA:53,0 +DA:55,0 +DA:57,0 +DA:60,0 +DA:66,0 +DA:70,0 +DA:74,0 +DA:76,0 +DA:79,0 +DA:83,1 +DA:86,0 +DA:88,0 +DA:89,0 +DA:93,1 +DA:96,0 +DA:98,0 +DA:103,0 +DA:105,0 +DA:107,0 +DA:109,0 +DA:112,0 +DA:113,0 +DA:114,0 +DA:115,0 +DA:117,0 +LF:51 +LH:18 +BRDA:21,1,0,1 +BRDA:21,1,1,0 +BRDA:114,2,0,0 +BRDA:114,2,1,0 +BRF:4 +BRH:1 +end_of_record +TN: +SF:/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_db/db.js +FN:6,(anonymous_1) +FNF:1 +FNH:0 +FNDA:0,(anonymous_1) +DA:1,1 +DA:2,1 +DA:3,1 +DA:6,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:12,0 +DA:13,0 +DA:17,0 +DA:39,1 +LF:11 +LH:5 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRDA:12,2,0,0 +BRDA:12,2,1,0 +BRF:4 +BRH:0 +end_of_record +TN: +SF:/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_db/studies.js +FN:7,(anonymous_1) +FNF:1 +FNH:0 +FNDA:0,(anonymous_1) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:7,1 +DA:8,0 +DA:10,0 +DA:13,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:17,0 +DA:25,1 +LF:13 +LH:6 +BRDA:16,1,0,0 +BRDA:16,1,1,0 +BRF:2 +BRH:0 +end_of_record +TN: +SF:/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_db/votes.js +FN:8,(anonymous_1) +FNF:1 +FNH:0 +FNDA:0,(anonymous_1) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:8,1 +DA:9,0 +DA:11,0 +DA:14,0 +DA:15,0 +DA:16,0 +DA:17,0 +DA:18,0 +DA:24,1 +LF:13 +LH:6 +BRDA:17,1,0,0 +BRDA:17,1,1,0 +BRF:2 +BRH:0 +end_of_record diff --git a/checkbox_test_generation/package.json b/checkbox_test_generation/package.json index 49f5d0b..3f19348 100644 --- a/checkbox_test_generation/package.json +++ b/checkbox_test_generation/package.json @@ -13,23 +13,23 @@ "author": "", "license": "ISC", "dependencies": { - "chai": "^4.1.2", - "iter-tools": "^1.3.0", - "lodash": "^4.17.4", - "mocha": "^3.5.0", - "randexp": "^0.4.6", - "request": "^2.85.0", - "mongoose": "^4.12.3", - "sinon": "^4.0.1", "archiver": "~0.4.6", "async": "^2.1.4", - "cors": "^2.7.1", + "chai": "^4.1.2", + "cors": "^2.8.4", "emailjs": "^1.0.8", - "express": "3.x", + "express": "^3.21.2", + "iter-tools": "^1.3.0", "jade": "^1.11.0", "json5": "^0.5.1", + "lodash": "^4.17.4", "marked": "0.3.9", + "mocha": "^3.5.0", "mongodb": "^2.2.22", + "mongoose": "^4.12.3", + "randexp": "^0.4.6", + "request": "^2.85.0", + "sinon": "^4.0.1", "underscore": "^1.8.3", "validator": "^6.2.1" }, diff --git a/checkbox_test_generation/src/constraint.js b/checkbox_test_generation/src/constraint.js index 9b52c1c..b5790a0 100644 --- a/checkbox_test_generation/src/constraint.js +++ b/checkbox_test_generation/src/constraint.js @@ -9,6 +9,7 @@ const randexp = require('randexp'); class Constraint { constructor(properties){ this.routePath = properties.routePath; + this.kind = properties.kind; /* this.expression = properties.expression; this.operator = properties.operator; this.value = properties.value; @@ -30,7 +31,7 @@ function constraints(filePath) { // Initialize function constraints directory let routeConstraints = []; - let url = "http://54.202.103.166"; + //let url = "http://54.202.103.166"; // Read input file and parse it with esprima. let buf = fs.readFileSync(filePath, "utf8"); @@ -49,12 +50,14 @@ function constraints(filePath) { if( child.type === "CallExpression" && child.callee.property && (child.callee.property.name === "get" || child.callee.property.name === "post")) { // Get expression from original source code: - let expression = (child.arguments[0].value); - let full_url = url + expression; + let expression = buf.substring(child.range[0], child.range[1]); + let url = (child.arguments[0].value); + //let full_url = url + expression; // Push a new constraint routeConstraints.push(new Constraint({ - routePath: full_url, + routePath: url, + kind: `'${child.callee.property.name}'` })); } diff --git a/checkbox_test_generation/src/testgenerator.js b/checkbox_test_generation/src/testgenerator.js index 11ef84b..7122e77 100644 --- a/checkbox_test_generation/src/testgenerator.js +++ b/checkbox_test_generation/src/testgenerator.js @@ -2,6 +2,7 @@ const _ = require('lodash'); const fs = require("fs"); +var base_url = "localhost:3002"; /** * Generate test cases based on the global object functionConstraints. @@ -16,15 +17,17 @@ function generateTestCases(filePath, routeConstraints){ content += `\nvar assert = require('assert');`; content += `\nvar sinon = require('sinon')`; content += `\nvar mongoose = require('mongoose')`; - content += `\n\\require('sinon-mongoose');`; - content += `\n\\var nock = require("nock"); \n\n\n`; + content += `\n//require('sinon-mongoose');`; + content += `\n//var nock = require("nock"); \n\n\n`; console.log(routeConstraints); routeConstraints.forEach(function(value){ console.log(value); - content += `request("${value.routePath}" , function(err, rep) { console.log(rep);} ); \n`; + let methodName = value.kind.toUpperCase(); + + content += `request({ url : '${base_url}${value.routePath}', method: ${methodName}}, function(error, response, body) { console.log(body);} ); \n`; }); @@ -34,6 +37,16 @@ function generateTestCases(filePath, routeConstraints){ } +// var myJSONObject = { ... }; +// request({ +// url: "http://josiahchoi.com/myjson", +// method: "POST", +// json: true, // <--Very important!!! +// body: myJSONObject +// }, function (error, response, body){ +// console.log(response); +// }); + // Export module.exports = generateTestCases; \ No newline at end of file diff --git a/checkbox_test_generation/test.js b/checkbox_test_generation/test.js index abda838..613c357 100644 --- a/checkbox_test_generation/test.js +++ b/checkbox_test_generation/test.js @@ -1,4 +1,4 @@ -let subject = require('G:\\CSC 519 - DevOps\\DevOps-Project\\checkbox_test_generation\\server.js'); +require('/Users/khantil/Developer/MCSStudy/DevOps/Project/DevOps-Project/checkbox_test_generation/mock_routes/study.js'); var request = require("request"); var assert = require('assert'); var sinon = require('sinon') @@ -7,17 +7,16 @@ var mongoose = require('mongoose') //var nock = require("nock"); -request("http://54.202.103.166/api/design/survey" , function(err, rep) { console.log(rep);} ); -/*request("http://54.202.103.166/api/study/load/:id" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/vote/status" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/status/:id" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/listing" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/create" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/vote/submit/" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/admin/:token" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/admin/download/:token" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/admin/assign/:token" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/admin/open/" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/admin/close/" , function(err, rep) { console.log(rep);} ); -request("http://54.202.103.166/api/study/admin/notify/" , function(err, rep) { console.log(rep);} ); -*/ \ No newline at end of file +// request({ url : 'localhost:3002/api/design/survey', method: 'POST'}, function(error, response, body) { console.log(body);} ); +request({ url : 'localhost:3002/api/study/load/:id', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/vote/status', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/status/:id', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/listing', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/create', method: 'POST'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/vote/submit/', method: 'POST'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/admin/:token', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/admin/download/:token', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/admin/assign/:token', method: 'GET'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/admin/open/', method: 'POST'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/admin/close/', method: 'POST'}, function(error, response, body) { console.log(body);} ); +// request({ url : 'localhost:3002/api/study/admin/notify/', method: 'POST'}, function(error, response, body) { console.log(body);} ); diff --git a/checkbox_test_generation/test_mock.js b/checkbox_test_generation/test_mock.js index 40262f1..5dcff3d 100644 --- a/checkbox_test_generation/test_mock.js +++ b/checkbox_test_generation/test_mock.js @@ -6,15 +6,14 @@ var new_storyboard = { }; var options = { - url: urlRoot + "/api/study/load/1", - method: 'GET', - json: new_storyboard, - headers: { - "content-type": "application/json" - } + url: urlRoot + "/api/study/load/5aabf0042ceed7549c53a386", + method: 'GET' }; -request(options,function(error, response, body){ +request({ + url: urlRoot + "/api/study/load/5aabf0042ceed7549c53a386", + method: 'GET' +},function(error, response, body){ if(error) console.log("\n ERROR ", error); else{