var apiTools2 = { evaluateResp: function (resp, expected, fn, sent_args) { fn = fn.substring(fn.indexOf("api/")+4, fn.indexOf(".php")); sent_args = Array.prototype.slice.call(sent_args); sent_args.pop(); if (expected) { if(resp != expected) { document.getElementById('testResults').innerHTML += "\nAPI error response for " + fn + "\n"; document.getElementById('testResults').innerHTML += "Arguments were: " + sent_args + "\n"; document.getElementById('testResults').innerHTML += "Expected: " + expected + "\n"; document.getElementById('testResults').innerHTML += "Received " + resp + "\n"; } else { //console.log("Correct response for " + fn + ' with arguments ' + sent_args); } } else { //console.log(resp); } }, evaluateLogin: function (resp, expected, fn, sent_args) { fn = fn.substring(fn.indexOf("api/")+4, fn.indexOf(".php")); sent_args = Array.prototype.slice.call(sent_args); sent_args.pop(); if (expected) { var respObj = $.parseJSON(resp); var expectedObj = $.parseJSON(expected); var correct = false; if (expectedObj['status'] == respObj['status'] ) { correct = true; if (expectedObj['status'] == 0 ) { correct = true; } else if (expectedObj['userID'] == expectedObj['userID']) { correct = true; } else { correct = false; } } else { correct = false; } if(!correct) { document.getElementById('testResults').innerHTML += "\nWRONG Response for " + fn + "\n"; document.getElementById('testResults').innerHTML += "Arguments were: " + sent_args + "\n"; document.getElementById('testResults').innerHTML += "Expected: " + expected + "\n"; document.getElementById('testResults').innerHTML += "Received " + resp + "\n"; //document.getElementById('testResults').innerHTML += msg + "\n\n"; } else { //console.log("Correct response for " + fn + ' with arguments ' + sent_args); } } else { document.getElementById('testResults').innerHTML += resp + "\n"; } }, evaluateTweets: function (resp, expected, fn, sent_args) { fn = fn.substring(fn.indexOf("api/")+4, fn.indexOf(".php")); sent_args = Array.prototype.slice.call(sent_args); sent_args.pop(); if (expected) { var respObj = $.parseJSON(resp); var expectedObj = $.parseJSON(expected); var match = true; var msg = ""; if (expectedObj['status'] == 1 && respObj['status'] == 1) { if ( expectedObj['tweets'].length == respObj['tweets'].length ) { for(var i = 0; i < expectedObj['tweets'].length; i++) { var tw1 = expectedObj['tweets'][i]; var tw2 = respObj['tweets'][i]; if (tw1['username'] != tw2['username'] || tw1['message'] != tw2['message'] || !tw2['creation_time']) { match = false; msg = "Mismatch in tweet details."; break; } } } else { match = false; msg = "Incorrect number of tweets"; } } else { match = (expectedObj['status'] == respObj['status']); msg = 'Status does not match'; } if(!match) { document.getElementById('testResults').innerHTML += "\nAPI error response for " + fn + "\n"; document.getElementById('testResults').innerHTML += "Arguments were: " + sent_args + "\n"; document.getElementById('testResults').innerHTML += "Expected: " + expected + "\n"; document.getElementById('testResults').innerHTML += "Received " + resp + "\n"; //console.log("\nAPI error response for " + fn); //console.log("Arguments were: " + sent_args); //console.log("Expected: " + expected); //console.log("Received " + resp); document.getElementById('testResults').innerHTML += msg + "\n\n"; } else { //console.log("Correct response for " + fn + ' with arguments ' + sent_args); } } else { //console.log(resp); } }, login: function (user, pw, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/login.php?username="+user+"&pw="+encodeURIComponent(pw), { async : false} ) .done(function(resp) { //apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); apiTools2.evaluateLogin(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, logout: function (expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/logout.php", { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, register: function (user, pw, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/register.php?username="+user+"&pw="+encodeURIComponent(pw), { async : false} ) .done(function(resp) { //apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); apiTools2.evaluateLogin(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, post: function (flit, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/post.php?flit="+encodeURIComponent(flit), { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, timeline: function (num, start, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; if(start < 0) start = (new Date()).getTime() + (1000*60*60*24*365*10); var jqxhr = $.ajax( "api/timeline.php?count="+num+"&start_time="+start, { async : false}) .done(function(resp) { apiTools2.evaluateTweets(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, user_tweets: function (user, num, start, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; if(start < 0) start = (new Date()).getTime() + (1000*60*60*24*365*10); var jqxhr = $.ajax( "api/user_tweets.php?user="+user+"&count="+num+"&start_time="+start, { async : false}) .done(function(resp) { apiTools2.evaluateTweets(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, user_tweets_paginated: function (user, num, expectedResponse2) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 5; var jqxhr = $.ajax( "api/user_tweets.php?user="+user+"&count="+num, { async : false}) .done(function(resp) { var respObj = $.parseJSON(resp); var tweets = respObj['tweets']; var last_time = tweets[tweets.length-1]['creation_time']; var jqxhr2 = $.ajax( "api/user_tweets.php?user="+user+"&count="+num+"&start_time="+last_time, { async : false}) .done(function(resp) { apiTools2.evaluateTweets(resp,expectedResponse2,this.url,my_args); }) }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, follow_user: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/follow.php?user="+user, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, unfollow_user: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/unfollow.php?user="+user, { async : false, processData: false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, check_if_follows: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/check_if_follows.php?user="+user, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_followers: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_followers.php?user="+user, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_followees: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_followees.php?user="+user, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_recommended: function (expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/recommend_users.php", { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, search: function (keyword, num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax( "api/search.php?count="+num+"&keyword="+encodeURIComponent(keyword), { async : false}) .done(function(resp) { //apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); apiTools2.evaluateTweets(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, user_search: function (name, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/user_search.php?username="+name, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_num_followers: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_num_followers.php?user="+user, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_num_followees: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_num_followees.php?user="+user, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_most_active: function (num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax( "api/most_active_users.php?count="+num, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_most_popular: function (num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax("api/most_popular_users.php?count="+num, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_hub_users: function (num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax( "api/get_hub_users.php?count="+num, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, reset: function (secret,expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/reset.php?secret="+secret, { async : false}) .done(function(resp) { apiTools2.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) } } var gradingTools = { numWrong: 0, numPoints: 0, numCorrect: 0, totalWrong: 0, totalPoints: 0, totalCorrect: 0, evaluateStagePoints: function(weight) { if(!weight) { weight = 1; } document.getElementById('testResults').innerHTML += gradingTools.numCorrect + "/" + gradingTools.numPoints + " (" + gradingTools.numWrong + " wrong)\n"; gradingTools.totalWrong += gradingTools.numWrong * weight; gradingTools.totalPoints += gradingTools.numPoints * weight; gradingTools.totalCorrect += gradingTools.numCorrect * weight; gradingTools.numWrong = 0; gradingTools.numPoints = 0; gradingTools.numCorrect = 0; $('#testResults').hide().show(); }, printResults: function() { document.getElementById('testResults').innerHTML += "\n\nFinal Results\n"; document.getElementById('testResults').innerHTML += gradingTools.totalCorrect + "/" + gradingTools.totalPoints + " (" + gradingTools.totalWrong + " points off)\n"; }, evaluateResp: function (resp, expected, fn, sent_args) { fn = fn.substring(fn.indexOf("api/")+4, fn.indexOf(".php")); sent_args = Array.prototype.slice.call(sent_args); sent_args.pop(); if (expected) { gradingTools.numPoints++; if(resp != expected) { document.getElementById('testResults').innerHTML += "\nWRONG Response for " + fn + "\n"; document.getElementById('testResults').innerHTML += "Arguments were: " + sent_args + "\n"; document.getElementById('testResults').innerHTML += "Expected: " + expected + "\n"; document.getElementById('testResults').innerHTML += "Received " + resp + "\n"; gradingTools.numWrong++; } else { //console.log("Correct response for " + fn + ' with arguments ' + sent_args); gradingTools.numCorrect++; } } else { document.getElementById('testResults').innerHTML += resp+"\n"; } }, evaluateLogin: function (resp, expected, fn, sent_args) { fn = fn.substring(fn.indexOf("api/")+4, fn.indexOf(".php")); sent_args = Array.prototype.slice.call(sent_args); sent_args.pop(); if (expected) { var respObj = $.parseJSON(resp); var expectedObj = $.parseJSON(expected); var correct = false; if (expectedObj['status'] == respObj['status'] ) { correct = true; if (expectedObj['status'] == 0 ) { correct = true; } else if (expectedObj['userID'] == expectedObj['userID']) { correct = true; } else { correct = false; } } else { correct = false; } gradingTools.numPoints++; if(!correct) { document.getElementById('testResults').innerHTML += "\nWRONG Response for " + fn + "\n"; document.getElementById('testResults').innerHTML += "Arguments were: " + sent_args + "\n"; document.getElementById('testResults').innerHTML += "Expected: " + expected + "\n"; document.getElementById('testResults').innerHTML += "Received " + resp + "\n"; //document.getElementById('testResults').innerHTML += msg + "\n\n"; gradingTools.numWrong++; } else { //console.log("Correct response for " + fn + ' with arguments ' + sent_args); gradingTools.numCorrect++; } } else { document.getElementById('testResults').innerHTML += resp + "\n"; } }, evaluateTweets: function (resp, expected, fn, sent_args) { fn = fn.substring(fn.indexOf("api/")+4, fn.indexOf(".php")); sent_args = Array.prototype.slice.call(sent_args); sent_args.pop(); if (expected) { var respObj = $.parseJSON(resp); var expectedObj = $.parseJSON(expected); var match = true; var msg = ""; if (expectedObj['status'] == 1 && respObj['status'] == 1) { if ( expectedObj['tweets'].length == respObj['tweets'].length ) { for(var i = 0; i < expectedObj['tweets'].length; i++) { var tw1 = expectedObj['tweets'][i]; var tw2 = respObj['tweets'][i]; if (tw1['username'] != tw2['username'] || tw1['message'] != tw2['message'] || !tw2['creation_time']) { match = false; msg = "Mismatch in tweet details."; break; } } } else { match = false; msg = "Incorrect number of tweets"; } } else { match = (expectedObj['status'] == respObj['status']); msg = 'Status does not match'; } gradingTools.numPoints++; if(!match) { document.getElementById('testResults').innerHTML += "\nWRONG Response for " + fn + "\n"; document.getElementById('testResults').innerHTML += "Arguments were: " + sent_args + "\n"; document.getElementById('testResults').innerHTML += "Expected: " + expected + "\n"; document.getElementById('testResults').innerHTML += "Received " + resp + "\n"; document.getElementById('testResults').innerHTML += msg + "\n\n"; gradingTools.numWrong++; } else { //console.log("Correct response for " + fn + ' with arguments ' + sent_args); gradingTools.numCorrect++; } } else { document.getElementById('testResults').innerHTML += resp + "\n"; } }, login: function (user, pw, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/login.php?username="+user+"&pw="+encodeURIComponent(pw), { async : false} ) .done(function(resp) { //gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); gradingTools.evaluateLogin(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, logout: function (expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/logout.php", { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, register: function (user, pw, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/register.php?username="+user+"&pw="+encodeURIComponent(pw), { async : false} ) .done(function(resp) { //gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); gradingTools.evaluateLogin(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, post: function (flit, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/post.php?flit="+encodeURIComponent(flit), { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, timeline: function (num, start, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; if(start < 0) start = (new Date()).getTime() + (1000*60*60*24*365*10); var jqxhr = $.ajax( "api/timeline.php?count="+num+"&start_time="+start, { async : false}) .done(function(resp) { gradingTools.evaluateTweets(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, timeline_paginated: function (num, expectedResponse2) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 5; var jqxhr = $.ajax( "api/timeline.php?count="+num, { async : false}) .done(function(resp) { var respObj = $.parseJSON(resp); var tweets = respObj['tweets']; var last_time = (new Date()).getTime() + (1000*60*60*24*365*10); if (respObj['tweets'] && tweets.length && tweets.length > 0) { var last_time = tweets[tweets.length-1]['creation_time']; } //var last_time = tweets[tweets.length-1]['creation_time']; var jqxhr2 = $.ajax( "api/timeline.php?count="+num+"&start_time="+last_time, { async : false}) .done(function(resp) { gradingTools.evaluateTweets(resp,expectedResponse2,this.url,my_args); }) }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, user_tweets: function (user, num, start, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; if(start < 0) start = (new Date()).getTime() + (1000*60*60*24*365*10); var jqxhr = $.ajax( "api/user_tweets.php?user="+user+"&count="+num+"&start_time="+start, { async : false}) .done(function(resp) { gradingTools.evaluateTweets(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, user_tweets_paginated: function (user, num, expectedResponse2) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 5; var jqxhr = $.ajax( "api/user_tweets.php?user="+user+"&count="+num, { async : false}) .done(function(resp) { var respObj = $.parseJSON(resp); var tweets = respObj['tweets']; var last_time = (new Date()).getTime() + (1000*60*60*24*365*10); if (respObj['tweets'] && tweets.length && tweets.length > 0) { var last_time = tweets[tweets.length-1]['creation_time']; } var jqxhr2 = $.ajax( "api/user_tweets.php?user="+user+"&count="+num+"&start_time="+last_time, { async : false}) .done(function(resp) { gradingTools.evaluateTweets(resp,expectedResponse2,this.url,my_args); }) }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, follow_user: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/follow.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, unfollow_user: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/unfollow.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, check_if_follows: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/check_if_follows.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_followers: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_followers.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_followees: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_followees.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_recommended: function (expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/recommend_users.php", { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, search: function (keyword, num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax( "api/search.php?count="+num+"&keyword="+encodeURIComponent(keyword), { async : false}) .done(function(resp) { //gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); gradingTools.evaluateTweets(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, user_search: function (name, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/user_search.php?username="+name, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_num_followers: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_num_followers.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_num_followees: function (user, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/get_num_followees.php?user="+user, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_most_active: function (num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax( "api/most_active_users.php?count="+num, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_most_popular: function (num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax("api/most_popular_users.php?count="+num, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, get_hub_users: function (num, expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; if(num < 0) num = 10; var jqxhr = $.ajax( "api/get_hub_users.php?count="+num, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) }, reset: function (secret,expectedResponse) { fn = arguments.callee.toString().substring(0, arguments.callee.toString().indexOf("(")); my_args = arguments; var jqxhr = $.ajax( "api/reset.php?secret="+secret, { async : false}) .done(function(resp) { gradingTools.evaluateResp(resp,expectedResponse,this.url,my_args); }) .fail(function() { console.log("The call to " + fn + " failed."); }) } } var testTools = { waste_time: function() { var s = 0 var t1 =(new Date()).getTime(); for (var i = 0; i < Math.pow(2,29); i++) { s += i; } var t2 =(new Date()).getTime(); }, testAccounts: function() { var password = "hellothere"; gradingTools.register("Jack123", password,'{"status":1,"userID":"Jack123"}') apiTools2.logout(); gradingTools.register("Jack123", password,'{"status":0}'); // Same Username and Password apiTools2.logout(); gradingTools.register("Jack123", password+"0",'{"status":0}') // Same Username different password apiTools2.logout(); apiTools2.register("Jack1234", password,'{"status":1,"userID":"Jack1234"}') // Different username same password apiTools2.logout(); gradingTools.register("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ", password,'{"status":0}') // too long username apiTools2.logout(); gradingTools.login("Jack123", password,'{"status":1,"userID":"Jack123"}') apiTools2.logout(); gradingTools.login("Jack123", password+"0",'{"status":0}') // should have failed registration before apiTools2.logout(); gradingTools.login("Jack1234", password,'{"status":1,"userID":"Jack1234"}') // check second login apiTools2.logout(); //gradingTools.login("Jack1234", password+"0",'{"status":0}') // wrong password //apiTools2.logout(); }, testReset: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); apiTools2.register("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.logout(); apiTools2.register("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.logout(); apiTools2.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.follow_user("Jack1234",'{"status":1}'); apiTools2.post("Hello?", '{"status":1}'); apiTools2.logout(); // Test Reset apiTools2.reset("15415Reset",'{"status":1}'); gradingTools.login("Jack123", password,'{"status":0}'); // Make sure account was deleted apiTools2.register("Jack123", password,'{"status":1,"userID":"Jack123"}'); // Make sure can register new account apiTools2.logout(); apiTools2.register("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.logout(); apiTools2.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); gradingTools.follow_user("Jack1234",'{"status":1}'); // Make sure can follow user gradingTools.user_tweets("Jack123",3,-1,'{"status":1,"tweets":[]}'); // Make sure posts were cleared apiTools2.logout(); }, // Test post, timeline, user tweets, search testTweets: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); apiTools2.register("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.logout(); apiTools2.register("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.logout(); apiTools2.register("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.logout(); apiTools2.register("Joe", password,'{"status":1,"userID":"Joe"}'); apiTools2.logout(); apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.post("Hello from Alex", '{"status":1}'); testTools.waste_time(); apiTools2.post("Hello from Alex #2", '{"status":1}'); testTools.waste_time(); apiTools2.logout(); apiTools2.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); //gradingTools.timeline(3,-1,'{"status":1,"tweets":[]}'); // Test empty timeline apiTools2.follow_user("Jack1234",'{"status":1}'); apiTools2.follow_user("Joe",'{"status":1}'); apiTools2.follow_user("Alex",'{"status":1}'); gradingTools.timeline(5,-1,'{"status":1,"tweets":[{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"},{"username":"Alex","message":"Hello from Alex","creation_time":"1396492364"}]}'); // Test basic include followed tweets in timeline gradingTools.post("Hello?", '{"status":1}'); testTools.waste_time(); // Test posting gradingTools.post("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum imperdiet turpis vitae tellus cursus pulvinar. Sed ullamcorper enim et dignissim fringilla. Donec urna nisl, molestie ut metus amet.", '{"status":0}'); testTools.waste_time(); // Test posting too long tweet gradingTools.timeline(5,-1,'{"status":1,"tweets":[{"username":"Jack123","message":"Hello?","creation_time":"1396492369"},{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"},{"username":"Alex","message":"Hello from Alex","creation_time":"1396492364"}]}'); // Test basic include own tweets in timeline with other people apiTools2.logout(); apiTools2.login("Joe", password,'{"status":1,"userID":"Joe"}'); apiTools2.post("Hello from Joe", '{"status":1}'); testTools.waste_time(); apiTools2.post("Hello from Joe again", '{"status":1}'); testTools.waste_time(); apiTools2.logout(); apiTools2.login("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.post("Hello from Jack1234", '{"status":1}'); testTools.waste_time(); apiTools2.post("Hello this is boring", '{"status":1}'); testTools.waste_time(); apiTools2.logout(); apiTools2.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); for(var i = 0; i < 10; i++) { apiTools2.post("Hello from Jack #" + i, '{"status":1}'); testTools.waste_time(); } gradingTools.timeline(8,-1,'{"status":1,"tweets":[{"username":"Jack123","message":"Hello from Jack #9","creation_time":"1396492395"},{"username":"Jack123","message":"Hello from Jack #8","creation_time":"1396492393"},{"username":"Jack123","message":"Hello from Jack #7","creation_time":"1396492391"},{"username":"Jack123","message":"Hello from Jack #6","creation_time":"1396492390"},{"username":"Jack123","message":"Hello from Jack #5","creation_time":"1396492388"},{"username":"Jack123","message":"Hello from Jack #4","creation_time":"1396492386"},{"username":"Jack123","message":"Hello from Jack #3","creation_time":"1396492385"},{"username":"Jack123","message":"Hello from Jack #2","creation_time":"1396492383"}]}'); // Test weird number of tweets to return gradingTools.timeline_paginated(10,'{"status":1,"tweets":[{"username":"Jack1234","message":"Hello this is boring","creation_time":"1396492379"},{"username":"Jack1234","message":"Hello from Jack1234","creation_time":"1396492376"},{"username":"Joe","message":"Hello from Joe again","creation_time":"1396492375"},{"username":"Joe","message":"Hello from Joe","creation_time":"1396492372"},{"username":"Jack123","message":"Hello?","creation_time":"1396492369"},{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"},{"username":"Alex","message":"Hello from Alex","creation_time":"1396492364"}]}'); // Test timeline paginated apiTools2.logout(); gradingTools.user_tweets('Jack123',4,-1,'{"status":1,"tweets":[{"username":"Jack123","message":"Hello from Jack #9","creation_time":"1396492395"},{"username":"Jack123","message":"Hello from Jack #8","creation_time":"1396492393"},{"username":"Jack123","message":"Hello from Jack #7","creation_time":"1396492391"},{"username":"Jack123","message":"Hello from Jack #6","creation_time":"1396492390"}]} '); // Test weird number of tweets to return gradingTools.user_tweets('Alex',4,-1,'{"status":1,"tweets":[{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"},{"username":"Alex","message":"Hello from Alex","creation_time":"1396492364"}]}'); // Test weird number of tweets to return (more than exists) gradingTools.user_tweets_paginated('Jack123',5,'{"status":1,"tweets":[{"username":"Jack123","message":"Hello from Jack #4","creation_time":"1396492386"},{"username":"Jack123","message":"Hello from Jack #3","creation_time":"1396492385"},{"username":"Jack123","message":"Hello from Jack #2","creation_time":"1396492383"},{"username":"Jack123","message":"Hello from Jack #1","creation_time":"1396492382"},{"username":"Jack123","message":"Hello from Jack #0","creation_time":"1396492380"}]}'); // Test user tweets paginated gradingTools.search("Alex",5,'{"status":1,"tweets":[{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"},{"username":"Alex","message":"Hello from Alex","creation_time":"1396492364"}]}'); // Test basic search //gradingTools.search("Hello",50,'{"status":1,"tweets":[{"username":"Jack123","message":"Hello from Jack #9","creation_time":"1396492395"},{"username":"Jack123","message":"Hello from Jack #8","creation_time":"1396492393"},{"username":"Jack123","message":"Hello from Jack #7","creation_time":"1396492391"},{"username":"Jack123","message":"Hello from Jack #6","creation_time":"1396492390"},{"username":"Jack123","message":"Hello from Jack #5","creation_time":"1396492388"},{"username":"Jack123","message":"Hello from Jack #4","creation_time":"1396492386"},{"username":"Jack123","message":"Hello from Jack #3","creation_time":"1396492385"},{"username":"Jack123","message":"Hello from Jack #2","creation_time":"1396492383"},{"username":"Jack123","message":"Hello from Jack #1","creation_time":"1396492382"},{"username":"Jack123","message":"Hello from Jack #0","creation_time":"1396492380"},{"username":"Jack1234","message":"Hello this is boring","creation_time":"1396492379"},{"username":"Jack1234","message":"Hello from Jack1234","creation_time":"1396492376"},{"username":"Joe","message":"Hello from Joe again","creation_time":"1396492375"},{"username":"Joe","message":"Hello from Joe","creation_time":"1396492372"},{"username":"Jack123","message":"Hello?","creation_time":"1396492369"},{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"},{"username":"Alex","message":"Hello from Alex","creation_time":"1396492364"}]}'); // Test basic search with large limit //gradingTools.search("#2",5,'{"status":1,"tweets":[{"username":"Jack123","message":"Hello from Jack #2","creation_time":"1396492383"},{"username":"Alex","message":"Hello from Alex #2","creation_time":"1396492366"}]}'); // Test search with hashtag gradingTools.search("ack1",25,'{"status":1,"tweets":[{"username":"Jack1234","message":"Hello from Jack1234","creation_time":"1396492376"}]}'); // Test search with middle of string //gradingTools.search("again",5,'{"status":1,"tweets":[{"username":"Joe","message":"Hello from Joe again","creation_time":"1396492375"}]}'); // Test search with end of tweet }, testFollowing: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); apiTools2.register("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.logout(); apiTools2.register("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.logout(); apiTools2.register("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.logout(); apiTools2.register("Joe", password,'{"status":1,"userID":"Joe"}'); apiTools2.logout(); apiTools2.register("Jill", password,'{"status":1,"userID":"Jill"}'); apiTools2.logout(); apiTools2.register("John", password,'{"status":1,"userID":"John"}'); apiTools2.logout(); apiTools2.register("Job", password,'{"status":1,"userID":"Job"}'); apiTools2.logout(); apiTools2.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); gradingTools.follow_user("Jack1234",'{"status":1}'); // Normal follow gradingTools.follow_user("Jack1234",'{"status":0}'); // Follow twice - should fail gradingTools.follow_user("Jack123",'{"status":0}'); // Follow self (should fail) gradingTools.follow_user("Jack",'{"status":0}'); // Follow not real user apiTools2.follow_user("Alex",'{"status":1}'); gradingTools.unfollow_user("Alex",'{"status":1}'); // Normal unfollow gradingTools.unfollow_user("Jack",'{"status":2}'); // Unfollow not real user gradingTools.unfollow_user("Joe",'{"status":2}'); // Unfollow not followed user gradingTools.check_if_follows("Jack1234", '{"status":1}') // Check if follows true gradingTools.check_if_follows("Alex", '{"status":0}') // CHeck if follows false gradingTools.get_followers("Alex",'{"status":1,"users":[]}') // Empty followers //gradingTools.get_followees("Alex", '{"status":1,"users":[]}') // Empty followees //gradingTools.get_num_followers("Alex", '{"status":1,"count":"0"}') gradingTools.get_num_followees("Alex", '{"status":1,"count":"0"}') apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.follow_user("Joe",'{"status":1}'); apiTools2.follow_user("Jill",'{"status":1}'); apiTools2.follow_user("John",'{"status":1}'); apiTools2.follow_user("Job",'{"status":1}'); apiTools2.logout(); apiTools2.login("Job", password,'{"status":1,"userID":"Job"}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.logout(); apiTools2.login("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.logout(); apiTools2.login("John", password,'{"status":1,"userID":"John"}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.logout(); gradingTools.get_followees("Jack123",'{"status":1,"users":["Alex","Jack1234","Jill","Job","Joe","John"]}') // Get non empty followers //gradingTools.get_followers("Alex",'{"status":1,"users":["Jack123","Jack1234","Job","John"]}') // Get non empty followees //gradingTools.get_num_followees("Jack123",'{"status":1,"count":"6"}') // Get num non empty followers gradingTools.get_num_followers("Alex",'{"status":1,"count":"4"}') // Get num non empty followees }, testUserSearch: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); users = ["Alex", "Allan", "Alan", "Joe", "Joseph", "phil", "Stephen", "Steven", "Slex"]; for( var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } gradingTools.user_search("Al",'{"status":1,"users":["Alan","Alex","Allan"]}'); // Test beginning gradingTools.user_search("ph",'{"status":1,"users":["Joseph","phil","Stephen"]}'); // Test middle gradingTools.user_search("lex",'{"status":1,"users":["Alex","Slex"]}');// Test end of name with ordering }, testRecommend: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); users = ["Alex", "Daniel", "Steven", "Adam", "Ashwin", "Niru", "Jianwei", "Trevor", "ZachC", "Heather", "Jessica", "Lindsey", "Lisa", "Siobahn", "Ryan" ]; for( var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.follow_user("Daniel",'{"status":1}'); apiTools2.follow_user("Steven",'{"status":1}'); apiTools2.follow_user("Adam",'{"status":1}'); apiTools2.follow_user("Ashwin",'{"status":1}'); apiTools2.follow_user("Niru",'{"status":1}'); apiTools2.follow_user("ZachC",'{"status":1}'); apiTools2.follow_user("Jessica",'{"status":1}'); apiTools2.follow_user("Lisa",'{"status":1}'); apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); apiTools2.follow_user("Siobahn",'{"status":1}'); apiTools2.follow_user("Lindsey",'{"status":1}'); apiTools2.logout(); apiTools2.login("Ashwin", password,'{"status":1,"userID":"Ashwin"}'); apiTools2.follow_user("Jianwei",'{"status":1}'); apiTools2.logout(); apiTools2.login("ZachC", password,'{"status":1,"userID":"ZachC"}'); apiTools2.follow_user("Heather",'{"status":1}'); apiTools2.logout(); apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); gradingTools.get_recommended('{"status":1,"users":["Heather","Jianwei","Lindsey","Siobahn"]}'); // Basic test sort by username everyone only followed once apiTools2.logout(); apiTools2.login("Niru", password,'{"status":1,"userID":"Niru"}'); apiTools2.follow_user("Jianwei",'{"status":1}'); apiTools2.logout(); apiTools2.login("Lisa", password,'{"status":1,"userID":"Lisa"}'); apiTools2.follow_user("Lindsey",'{"status":1}'); apiTools2.logout(); apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); gradingTools.get_recommended('{"status":1,"users":["Jianwei","Lindsey","Heather","Siobahn"]}'); // Basic test sort by number of people apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.logout(); apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); gradingTools.get_recommended('{"status":1,"users":["Jianwei","Lindsey","Heather","Siobahn"]}'); // Don't include current user in result apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); apiTools2.follow_user("Lisa",'{"status":1}'); apiTools2.follow_user("Daniel",'{"status":1}'); apiTools2.unfollow_user("Alex",'{"status":1}'); apiTools2.logout(); apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); gradingTools.get_recommended('{"status":1,"users":["Jianwei","Lindsey","Heather","Siobahn"]}'); // Don't include people I already follow apiTools2.logout(); }, testMostActive: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); users = ["Alex", "Daniel", "Steven", "Adam", "Ashwin", "Niru", "Jianwei", "Trevor", "ZachC", "Heather", "Jessica", "Lindsey", "Lisa", "Siobahn", "Ryan" ]; for( var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); for (var i = 0; i < 5; i++) { apiTools2.post("yo yo"); waste_time(); } apiTools2.logout(); apiTools2.login("Lisa", password,'{"status":1,"userID":"Lisa"}'); for (var i = 0; i < 4; i++) { apiTools2.post("hi hi"); waste_time(); } apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); for (var i = 0; i < 4; i++) { apiTools2.post("hi hi"); waste_time(); } apiTools2.logout(); apiTools2.login("Ashwin", password,'{"status":1,"userID":"Ashwin"}'); for (var i = 0; i < 15; i++) { apiTools2.post("yoyoyoyoyo"); waste_time(); } apiTools2.logout(); apiTools2.login("Niru", password,'{"status":1,"userID":"Niru"}'); for (var i = 0; i < 2; i++) { apiTools2.post("yoooooooo"); waste_time(); } apiTools2.logout(); apiTools2.login("Daniel", password,'{"status":1,"userID":"Daniel"}'); for (var i = 0; i < 7; i++) { apiTools2.post("hollla"); waste_time(); } apiTools2.logout(); apiTools2.login("Jianwei", password,'{"status":1,"userID":"Jianwei"}'); for (var i = 0; i < 10; i++) { apiTools2.post("hackernews"); waste_time(); } apiTools2.logout(); gradingTools.get_most_active(3,'{"status":1,"users":["Ashwin","Jianwei","Daniel"]}') // Basic get top 3 gradingTools.get_most_active(7,'{"status":1,"users":["Ashwin","Jianwei","Daniel","Alex","Jessica","Lisa","Niru"]}') // Need to break ties in spelling }, testMostPopular: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); users = ["Alex", "Daniel", "Steven", "Adam", "Ashwin", "Niru", "Jianwei", "Trevor", "ZachC", "Heather", "Jessica", "Lindsey", "Lisa", "Siobahn", "Ryan" ]; for( var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } for( var i = 0; i < users.length; i++) { if(users[i] != "Jessica") { apiTools2.login(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.follow_user("Jessica",'{"status":1}'); apiTools2.logout(); } } for( var i = 4; i < users.length; i++) { apiTools2.login(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.follow_user("Daniel",'{"status":1}'); apiTools2.logout(); } apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.follow_user("Ashwin",'{"status":1}'); apiTools2.follow_user("Lisa",'{"status":1}'); apiTools2.follow_user("Lindsey",'{"status":1}'); apiTools2.logout(); apiTools2.login("Daniel", password,'{"status":1,"userID":"Daniel"}'); apiTools2.follow_user("Ashwin",'{"status":1}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.follow_user("Lisa",'{"status":1}'); apiTools2.follow_user("Lindsey",'{"status":1}'); apiTools2.logout(); apiTools2.login("Steven", password,'{"status":1,"userID":"Steven"}'); apiTools2.follow_user("Ashwin",'{"status":1}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.logout(); apiTools2.login("Adam", password,'{"status":1,"userID":"Adam"}'); apiTools2.follow_user("Ashwin",'{"status":1}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.logout(); gradingTools.get_most_popular(2,'{"status":1,"users":["Jessica","Daniel"]}') // Basic get top 2 gradingTools.get_most_popular(4,'{"status":1,"users":["Jessica","Daniel","Alex","Ashwin"]}') // Need to break ties in spelling gradingTools.get_most_popular(5,'{"status":1,"users":["Jessica","Daniel","Alex","Ashwin","Lindsey"]}') // Need to break ties in spelling }, testMostConnected: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); users = ["Alex", "Daniel", "Steven", "Adam", "Ashwin", "Niru", "Jianwei", "Trevor", "ZachC", "Heather", "Jessica", "Lindsey", "Lisa", "Siobahn", "Ryan" ]; for (var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } apiTools2.login("Lisa", password,'{"status":1,"userID":"Lisa"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Lindsey", password,'{"status":1,"userID":"Lindsey"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Siobahn", password,'{"status":1,"userID":"Siobahn"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); apiTools2.follow_user('Alex','{"status":1}'); apiTools2.follow_user('Daniel','{"status":1}'); apiTools2.logout(); apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.follow_user('Daniel','{"status":1}'); apiTools2.follow_user('Adam','{"status":1}'); apiTools2.follow_user('Steven','{"status":1}'); apiTools2.logout(); apiTools2.login("Daniel", password,'{"status":1,"userID":"Daniel"}'); apiTools2.follow_user('Ashwin','{"status":1}'); apiTools2.logout(); gradingTools.get_hub_users(3,'{"status":1,"users":["Jessica","Alex","Daniel"]}') // Basic top 3 apiTools2.login("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.follow_user('Niru','{"status":1}'); apiTools2.logout(); gradingTools.get_hub_users(3,'{"status":1,"users":["Alex","Jessica","Daniel"]}') // Basic top 3, break tie by spelling apiTools2.reset("15415Reset"); users = ["Alex", "Daniel", "Steven", "Adam", "Ashwin", "Niru", "Jianwei", "Trevor", "ZachC", "Heather", "Jessica", "Lindsey", "Lisa", "Siobahn", "Ryan" ]; for (var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } for( var i = 2; i < 7; i++) { apiTools2.login(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.follow_user("Daniel",'{"status":1}'); apiTools2.logout(); } apiTools2.login("Daniel", password,'{"status":1,"userID":"Daniel"}'); for( var i = 2; i < 7; i++) { apiTools2.follow_user(users[i],'{"status":1}'); } apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); for( var i = 0; i < 4; i++) { apiTools2.follow_user(users[i],'{"status":1}'); } apiTools2.logout(); apiTools2.login("Lisa", password,'{"status":1,"userID":"Lisa"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Lindsey", password,'{"status":1,"userID":"Lindsey"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Siobahn", password,'{"status":1,"userID":"Siobahn"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); gradingTools.get_hub_users(2,'{"status":1,"users":["Daniel","Jessica"]}') // Make sure that you appropriately add both in and out degree and not just union apiTools2.reset("15415Reset"); users = ["Alex", "Daniel", "Steven", "Adam", "Ashwin", "Niru", "Jianwei", "Trevor", "ZachC", "Heather", "Jessica", "Lindsey", "Lisa", "Siobahn", "Ryan" ]; for (var i = 0; i < users.length; i++) { apiTools2.register(users[i], password,'{"status":1,"userID":"'+users[i]+'"}'); apiTools2.logout(); } apiTools2.login("Ryan", password,'{"status":1,"userID":"Ryan"}'); for( var i = 0; i < users.length - 1; i++) { apiTools2.follow_user(users[i],'{"status":1}'); } apiTools2.logout(); apiTools2.login("Lisa", password,'{"status":1,"userID":"Lisa"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Lindsey", password,'{"status":1,"userID":"Lindsey"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Siobahn", password,'{"status":1,"userID":"Siobahn"}'); apiTools2.follow_user('Jessica','{"status":1}'); apiTools2.logout(); apiTools2.login("Jessica", password,'{"status":1,"userID":"Jessica"}'); apiTools2.follow_user('Alex','{"status":1}'); apiTools2.logout(); gradingTools.get_hub_users(2,'{"status":1,"users":["Ryan","Jessica"]}') // Make sure to join if one side is 0 }, // Test SQL Injection testSQLInjection: function() { var password = "hellothere"; apiTools2.reset("15415Reset"); apiTools2.register("Alex", password,'{"status":1,"userID":"Alex"}'); apiTools2.logout(); apiTools2.register("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.logout(); apiTools2.register("Jack1234", password,'{"status":1,"userID":"Jack1234"}'); apiTools2.logout(); apiTools2.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.follow_user("Jack1234",'{"status":1}'); apiTools2.follow_user("Alex",'{"status":1}'); apiTools2.post("Hello?", '{"status":1}'); apiTools2.unfollow_user("Blah' OR 1=1; --"); // Unfollow hack apiTools2.unfollow_user('Blah" OR 1=1; --'); // Unfollow hack gradingTools.check_if_follows("Jack1234", '{"status":1}') // Check if follows true apiTools2.logout(); gradingTools.login("Jack123'; --","5",'{"status":0}'); apiTools2.logout(); gradingTools.login('Jack123"; --',"5",'{"status":0}'); apiTools2.logout(); gradingTools.user_search("z' OR 1=1; --",'{"status":1,"users":[]}'); apiTools2.user_tweets("Jack123",3,'5; drop table Users cascade; --'); gradingTools.login("Jack123", password,'{"status":1,"userID":"Jack123"}'); apiTools2.logout(); }, runTests: function() { apiTools2.reset("15415Reset"); console.log("Test Accounts"); document.getElementById('testResults').innerHTML += "Test Accounts\n"; testTools.testAccounts(); // Test Register & Login: 8 pts; gradingTools.evaluateStagePoints(); console.log("Test Reset"); document.getElementById('testResults').innerHTML += "Test Reset\n"; testTools.testReset(); // Test Resetting all 3 tables: 3pts gradingTools.evaluateStagePoints(); console.log("Test Tweets"); document.getElementById('testResults').innerHTML += "Test Tweets\n"; testTools.testTweets(); // Test post, timeline, user tweets, search: 15pts gradingTools.evaluateStagePoints(); console.log("Test Following"); document.getElementById('testResults').innerHTML += "Test Following\n"; testTools.testFollowing(); // Test follow, unfollow, check_if_follows, get_followers, get_followees, get_num_followers, get_num_followees: 17pts gradingTools.evaluateStagePoints(); console.log("Test User Search"); document.getElementById('testResults').innerHTML += "Test User Search\n"; testTools.testUserSearch(); // Test user search: 3pts gradingTools.evaluateStagePoints(); console.log("Test Recommendation"); document.getElementById('testResults').innerHTML += "Test Recommendation\n"; testTools.testRecommend(); // Test recommendation: 4pts gradingTools.evaluateStagePoints(); console.log("Test Most Active Users"); document.getElementById('testResults').innerHTML += "Test Most Active Users\n"; testTools.testMostActive(); // Test most active: 2pts gradingTools.evaluateStagePoints(); console.log("Test Most Popular"); document.getElementById('testResults').innerHTML += "Test Most Popular\n"; testTools.testMostPopular(); // Test most popular: 3pts gradingTools.evaluateStagePoints(); console.log("Test Most Connected (Hub users)"); document.getElementById('testResults').innerHTML += "Test Most Connected (Hub users)\n"; testTools.testMostConnected(); // Test most connected: 4pts gradingTools.evaluateStagePoints(); console.log("Test SQL Injection"); document.getElementById('testResults').innerHTML += "Test SQL Injection\n"; testTools.testSQLInjection(); gradingTools.evaluateStagePoints(); apiTools2.reset("15415Reset"); gradingTools.printResults(); //generateData(); }, runTestsPart1: function() { console.log( (new Date()).getTime() ); apiTools2.reset("15415Reset"); console.log("Test Accounts"); document.getElementById('testResults').innerHTML += "Test Accounts\n"; testTools.testAccounts(); // Test Register & Login: 8 pts; gradingTools.evaluateStagePoints(); console.log("Test Reset"); document.getElementById('testResults').innerHTML += "Test Reset\n"; testTools.testReset(); // Test Resetting all 3 tables: 3pts gradingTools.evaluateStagePoints(); console.log("Test Tweets"); window.setTimeout(testTools.runTestsPart12, 300); }, runTestsPart12: function() { document.getElementById('testResults').innerHTML += "Test Tweets\n"; testTools.testTweets(); // Test post, timeline, user tweets, search: 15pts gradingTools.evaluateStagePoints(); console.log("Test Following"); window.setTimeout(testTools.runTestsPart2, 300); }, runTestsPart2: function() { document.getElementById('testResults').innerHTML += "Test Following\n"; testTools.testFollowing(); // Test follow, unfollow, check_if_follows, get_followers, get_followees, get_num_followers, get_num_followees: 17pts gradingTools.evaluateStagePoints(); console.log("Test User Search"); document.getElementById('testResults').innerHTML += "Test User Search\n"; testTools.testUserSearch(); // Test user search: 3pts gradingTools.evaluateStagePoints(); console.log("Test Recommendation"); document.getElementById('testResults').innerHTML += "Test Recommendation\n"; testTools.testRecommend(); // Test recommendation: 4pts gradingTools.evaluateStagePoints(); console.log("Test Most Active Users"); window.setTimeout(testTools.runTestsPart22, 300); }, runTestsPart22: function() { document.getElementById('testResults').innerHTML += "Test Most Active Users\n"; testTools.testMostActive(); // Test most active: 2pts gradingTools.evaluateStagePoints(); console.log("Test Most Popular"); window.setTimeout(testTools.runTestsPart3, 300); }, runTestsPart3: function() { document.getElementById('testResults').innerHTML += "Test Most Popular\n"; testTools.testMostPopular(); // Test most popular: 3pts gradingTools.evaluateStagePoints(); console.log("Test Most Connected (Hub users)"); document.getElementById('testResults').innerHTML += "Test Most Connected (Hub users)\n"; testTools.testMostConnected(); // Test most connected: 4pts gradingTools.evaluateStagePoints(); console.log("Test SQL Injection"); document.getElementById('testResults').innerHTML += "Test SQL Injection\n"; testTools.testSQLInjection(); gradingTools.evaluateStagePoints(); apiTools2.reset("15415Reset"); gradingTools.printResults(); console.log( (new Date()).getTime() ); } }; function addBox() { var textbox = document.createElement('textarea'); textbox.id = 'testResults'; textbox.style.position = "fixed"; textbox.style.left = 0; textbox.style.top = 0; textbox.rows = 20; textbox.cols = 100; document.body.appendChild(textbox); document.getElementById('testResults').innerHTML = "Running tests on " + document.URL + "\n"; } addBox(); window.setTimeout(testTools.runTestsPart1, 100);