Best JavaScript code snippet using best
github-service.js
Source:github-service.js
1 /***************************************************************************/2 /* Augeo.io is a web application that uses Natural Language Processing to */3 /* classify a user's internet activity into different 'skills'. */4 /* Copyright (C) 2016 Brian Redd */5 /* */6 /* This program is free software: you can redistribute it and/or modify */7 /* it under the terms of the GNU General Public License as published by */8 /* the Free Software Foundation, either version 3 of the License, or */9 /* (at your option) any later version. */10 /* */11 /* This program is distributed in the hope that it will be useful, */12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */14 /* GNU General Public License for more details. */15 /* */16 /* You should have received a copy of the GNU General Public License */17 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */18 /***************************************************************************/19 /***************************************************************************/20 /* Description: Unit test cases for service/github-service */21 /***************************************************************************/22 // Required libraries23 var Assert = require('assert');24 var Should = require('should');25 // Required local modules26 var AugeoDB = require('../../../src/model/database');27 var Common = require('../../data/common');28 var GithubData = require('../../data/github-data');29 var GithubInterfaceService = require('../../../src/interface-service/github-interface-service');30 var GithubService = require('../../../src/service/github-service');31 // Global variables32 var Activity = AugeoDB.model('ACTIVITY');33 var Commit = AugeoDB.model('GITHUB_COMMIT');34 var User = AugeoDB.model('AUGEO_USER');35 var GithubUser = AugeoDB.model('GITHUB_USER');36 // addCommits37 it('should add commits to the GITHUB_COMMIT collection -- addCommits()', function(done) {38 // Get initial count of commits in GITHUB_COMMIT collection39 Commit.getCommitCount(Common.logData, function(initialCommitCount) {40 // Try to add empty array of commits41 GithubService.addCommits(GithubData.USER_GITHUB.screenName, new Array(), Common.logData, function() {42 // Get count of commits in GITHUB_COMMIT collection to verify none were added43 Commit.getCommitCount(Common.logData, function(noneAddedCount) {44 Assert.strictEqual(noneAddedCount, initialCommitCount);45 // Get augeo userId for USER and initial experience46 User.getUserSecretWithUsername(Common.USER.username, Common.logData, function(user) {47 var initialExperience = user.skill.experience;48 // Use interface service to get extracted commits49 GithubInterfaceService.getCommits(user, 'accessToken', 'path', '1', null, Common.logData, function(result) {50 Assert.strictEqual(result.commits.length, 4);51 // Add commits52 GithubService.addCommits(GithubData.USER_GITHUB.screenName, result.commits, Common.logData, function() {53 // Verify commit count54 Commit.getCommitCount(Common.logData, function(afterAddCount) {55 Assert.strictEqual(afterAddCount, initialCommitCount + 4);56 // Verify commits are in GITHUB_COMMIT collection57 Commit.getLatestCommit(GithubData.USER_GITHUB.screenName, Common.logData, function(latestCommit) {58 Assert.equal(latestCommit.eventId, result.commits[0].eventId);59 // Verify commits are in ACTIVITY collection60 Activity.getActivity(user._id, latestCommit._id, Common.logData, function(activity) {61 Should.exist(activity);62 // Sum up new commits experience63 var sum = 0;64 for(var i = 0; i < result.commits.length; i++) {65 sum += parseInt(result.commits[i].experience);66 }67 // Verify user's overall experience and technology experience were increased68 User.getUserWithUsername(Common.USER.username, Common.logData, function(userAfter) {69 Assert.strictEqual(userAfter.skill.experience, initialExperience + sum);70 done();71 });72 });73 });74 });75 });76 });77 });78 });79 });80 });81 });82 // addUser83 it('should add a Github user to the GITHUB_USER collection -- addUser()', function(done) {84 GithubService.addUser(Common.USER.username, GithubData.USER_GITHUB, Common.logData, function(){}, function(message0) {85 Assert.strictEqual(message0, 'Invalid Github user');86 User.getUserWithUsername(Common.USER.username, Common.logData, function(user) {87 var missingGithubId = {88 augeoUser: user._id,89 accessToken: GithubData.USER_GITHUB.accessToken,90 screenName: GithubData.USER_GITHUB.screenName91 };92 GithubService.addUser(Common.USER.username, missingGithubId, Common.logData, function(){}, function(message1) {93 Assert.strictEqual(message1, 'Invalid Github user');94 var missingScreenName = {95 augeoUser: user._id,96 githubId: GithubData.USER_GITHUB.githubId,97 accessToken: GithubData.USER_GITHUB.accessToken98 };99 GithubService.addUser(Common.USER.username, missingScreenName, Common.logData, function(){}, function(message2) {100 Assert.strictEqual(message2, 'Invalid Github user');101 var missingAccessToken = {102 augeoUser: user._id,103 githubId: GithubData.USER_GITHUB.githubId,104 screenName: GithubData.USER_GITHUB.screenName105 };106 GithubService.addUser(Common.USER.username, missingAccessToken, Common.logData, function(){}, function(message3) {107 Assert.strictEqual(message3, 'Invalid Github user');108 var valid = {109 augeoUser: user._id,110 githubId: GithubData.USER_GITHUB.githubId,111 accessToken: GithubData.USER_GITHUB.accessToken,112 screenName: GithubData.USER_GITHUB.screenName113 };114 GithubService.addUser(Common.USER.username, valid, Common.logData, function(){115 User.getUserWithUsername(Common.USER.username, Common.logData, function(updatedUser) {116 Assert.strictEqual(updatedUser.github.githubId, GithubData.USER_GITHUB.githubId);117 done();118 });119 }, function(){});120 });121 });122 });123 });124 });125 });126 // checkExistingScreenName127 it('should check if the specified Github user exists in the GITHUB_USER collection -- checkExistingScreenName()', function(done) {128 // Screen name that doesn't exist129 var screenName0 = 'doesntExist';130 GithubService.checkExistingScreenName(screenName0, Common.logData, function(doesExist0) {131 Assert.strictEqual(doesExist0, false);132 // Valid existing screen name133 GithubService.checkExistingScreenName(GithubData.USER_GITHUB.screenName, Common.logData, function(doesExist1) {134 Assert.strictEqual(doesExist1, true);135 done();136 });137 });138 });139 // getLatestCommitEventId140 it('should get the latest Commit Event ID -- getLatestCommitEventId()', function(done) {141 // Get latest Commit ID142 GithubService.getLatestCommitEventId(GithubData.USER_GITHUB.screenName, Common.logData, function(initialCommitId) {143 User.getUserSecretWithUsername(Common.USER.username, Common.logData, function(user) {144 GithubInterfaceService.getCommits(user, 'accessToken', 'path', '1', null, Common.logData, function(result) {145 var commits = new Array();146 var commit = result.commits[0];147 commit.eventId = 4;148 commits.push(commit);149 // Add Commit150 GithubService.addCommits(GithubData.USER_GITHUB.screenName, commits, Common.logData, function() {151 // Get latest Commit ID and verify it matches the added commit152 GithubService.getLatestCommitEventId(GithubData.USER_GITHUB.screenName, Common.logData, function(latestCommitId) {153 initialCommitId.should.not.be.eql(latestCommitId);154 Assert.equal(latestCommitId, 4);155 done();156 });157 });158 });159 });160 });161 });162 // loopThroughUsersQueueData163 it('should loop through all users queue data and execute a callback for each user -- loopThroughUsersQueueData()', function(done) {164 // Verify there is only one Github user or else done will get called multiple times165 GithubUser.getAllUsers(Common.logData, function(users) {166 Assert.strictEqual(users.length, 1);167 GithubService.loopThroughUsersQueueData(Common.logData, function(queueData) {168 Should.exist(queueData.user.screenName);169 Should.exist(queueData.eventId);170 done();171 });172 });173 });174 // removeUser175 it('should remove Github user from GITHUB_USER collection -- removeUser()', function(done) {176 // Invalid AugeoUser ID177 GithubService.removeUser(undefined, Common.logData, function () {178 }, function (code, message) {179 Assert.strictEqual(message, 'Invalid AugeoUser ID');180 GithubUser.getUserWithScreenName(GithubData.USER_GITHUB.screenName, Common.logData, function (user0) {181 // Valid AugeoUser ID182 GithubService.removeUser(user0.augeoUser, Common.logData, function (removedUser) {183 Assert.strictEqual(removedUser.screenName, GithubData.USER_GITHUB.screenName);184 // Verify Github user is no longer in GITHUB_USER collection185 GithubUser.getUserWithScreenName(GithubData.USER_GITHUB.screenName, Common.logData, function (user1) {186 Should.not.exist(user1);187 // Verify AugeoUser no longer has reference to GITHUB_USER188 User.getUserWithUsername(Common.USER.username, Common.logData, function (user2) {189 Should.not.exist(user2.github);190 done();191 });192 });193 });194 });195 });...
GithubRepoWidget.js
Source:GithubRepoWidget.js
1/*!2 GitHub-Repo-Widget.js - Not depend on jQuery or Other Framework.3 License: MIT4*/5(function() {6 var rendered = 'github-widget-rendered',7 cssStr = '.path-divider{margin:0 .25em}.github-box *{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;}.github-box{font-family:helvetica,arial,sans-serif;font-size:13px;line-height:18px;background:#fafafa;border:1px solid #ddd;color:#666;border-radius:3px}.github-box a{color:#4183c4;border:0;text-decoration:none}.github-box .github-box-title{position:relative;border-bottom:1px solid #ddd;border-radius:3px 3px 0 0;background:#fcfcfc;background:-moz-linear-gradient(#fcfcfc,#ebebeb);background:-webkit-linear-gradient(#fcfcfc,#ebebeb);}.github-box .github-box-title h3{word-wrap:break-word;font-family:helvetica,arial,sans-serif;font-weight:normal;font-size:16px;color:gray;margin:0;padding:10px 10px 10px 30px;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAXBAMAAAD0LQLXAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAASUExURQAAAL29vc3NzcLCwsjIyNbW1pvTNOEAAAABdFJOUwBA5thmAAAATElEQVQI12MIFoQAEQZFYwcGEGBkUDRUQLCcsYjRXhbqKkEGZQYGqJgSnKXCwGgsAGYpqyobG4WGhioyhBhDgClI3EQAqpaZwQBEAQARmA4G2o55nQAAAABJRU5ErkJggg==) 7px center no-repeat; width: auto;}.github-box .github-box-title h3 .repo{font-weight:bold}.github-box .github-box-title .github-stats{float:right;position:absolute;top:8px;right:10px;font-size:11px;font-weight:bold;line-height:21px;height:auto;min-height:21px}.github-box .github-box-title .github-stats a{display:inline-block;height:21px;color:#666;border:1px solid #ddd;border-radius:3px;padding:0 5px 0 18px;background: white url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAqBAMAAABB12bjAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAYUExURf///5mZmdbW1u/v7/r6+rGxscXFxaSkpHLccIMAAABsSURBVBjTY2CgBmBODTOAsFgSi9TFHMBMc1Fmk8BiEItJUMhQWFFQAZXJoC7q7FJYhNBmgG7YQAIWMYTvEExXIbh8oAJWQQe4IGsIlKmowAZVwaKowgxlMgkKmwtCjRAUYBSEqnVkYBAm39EALMwNXwql3eYAAAAASUVORK5CYII=) no-repeat}.github-box .github-box-title .github-stats .watchers{border-right:1px solid #ddd}.github-box .github-box-title .github-stats .forks{background-position:-4px -21px;padding-left:15px}.github-box .github-box-content{padding:10px;font-weight:300}.github-box .github-box-content p{margin:0}.github-box .github-box-content .link{font-weight:bold}.github-box .github-box-download{position:relative;border-top:1px solid #ddd;background:white;border-radius:0 0 3px 3px;padding:10px;height:auto;min-height:24px;}.github-box .github-box-download .updated{word-wrap:break-word;margin:0;font-size:11px;color:#666;line-height:24px;font-weight:300;width:auto}.github-box .github-box-download .updated strong{font-weight:bold;color:#000}.github-box .github-box-download .download{float:right;position:absolute;top:10px;right:10px;height:24px;line-height:24px;font-size:12px;color:#666;font-weight:bold;text-shadow:0 1px 0 rgba(255,255,255,0.9);padding:0 10px;border:1px solid #ddd;border-bottom-color:#bbb;border-radius:3px;background:#f5f5f5;background:-moz-linear-gradient(#f5f5f5,#e5e5e5);background:-webkit-linear-gradient(#f5f5f5,#e5e5e5);}.github-box .github-box-download .download:hover{color:#527894;border-color:#cfe3ed;border-bottom-color:#9fc7db;background:#f1f7fa;background:-moz-linear-gradient(#f1f7fa,#dbeaf1);background:-webkit-linear-gradient(#f1f7fa,#dbeaf1);}@media (max-width: 767px) {.github-box .github-box-title{height:auto;min-height:60px}.github-box .github-box-title h3 .repo{display:block}.github-box .github-box-title .github-stats a{display:block;clear:right;float:right;}.github-box .github-box-download{height:auto;min-height:46px;}.github-box .github-box-download .download{top:32px;}}';8 function _getAttribute(node, name, defaultValue) {9 return node.getAttribute(name) || defaultValue;10 }11 function _querySelector(dom, sel) {12 return dom.querySelector(sel);13 }14 function _setHtml(dom, h) {15 dom.innerHTML = h;16 }17 function _appendCss() {18 var x = document.createElement('div');19 x.innerHTML = 'x<style>'+cssStr+'</style>';20 document.getElementsByTagName('head')[0].appendChild(x.lastChild);21 }22 function _renderGitHubWidget(repoEle, repo) {23 repo = JSON.parse(repo);24 _setHtml(_querySelector(repoEle, '.watchers'), repo.watchers);25 _setHtml(_querySelector(repoEle, '.forks'), repo.forks);26 _setHtml(_querySelector(repoEle, '.description span'), repo.description);27 _setHtml(_querySelector(repoEle, '.updated'), 'Latest commit to the <strong>' + repo.default_branch+ '</strong> branch on <strong>' + repo.pushed_at.substring(0, 10) + '</strong>');28 if(repo.homepage !== null) {29 _setHtml(_querySelector(repoEle, '.link'), '<a href="'+ repo.homepage +'">'+ repo.homepage +'</a>');30 }31 repoEle.setAttribute(rendered, '1');32 }33 function _ajaxReq(repoEle, repo) {34 var xmlhttp;35 if (window.XMLHttpRequest) {36 //code for IE7,firefox chrome and above37 xmlhttp = new XMLHttpRequest();38 } else {39 //code for Internet Explorer40 xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');41 }42 xmlhttp.onreadystatechange = function() {43 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {44 _renderGitHubWidget(repoEle, xmlhttp.responseText);45 } else {46 }47 };48 xmlhttp.open('GET', 'https://api.github.com/repos/' + repo, true);49 xmlhttp.send();50 }51 function _init() {52 var github_eles = document.querySelectorAll('.github-widget'), repoEle, repo, vendorName, repoName, vendorUrl, repoUrl, widget;53 for (var i = 0; i < github_eles.length; i++) {54 repoEle = github_eles[i];55 if (! _getAttribute(repoEle, rendered, '')) {56 repo = _getAttribute(repoEle, 'data-repo', ''),57 vendorName = repo.split('/')[0],58 repoName = repo.split('/')[1],59 vendorUrl = 'http://github.com/' + vendorName,60 repoUrl = 'http://github.com/' + vendorName + '/' + repoName;61 widget = '<div class="github-box repo">'+62 '<div class="github-box-title">'+63 '<h3>'+64 '<a class="owner" href="' + vendorUrl + '" title="' + vendorUrl + '">' + vendorName + '</a>'+65 '<span class="path-divider">/</span>'+66 '<a class="repo" href="' + repoUrl + '" title="' + repoUrl + '">' + repoName + '</a>'+67 '</h3>'+68 '<div class="github-stats">'+69 '<span class="github-text">Star </span>'+70 '<a class="watchers" href="' + repoUrl + '/watchers" title="See watchers">?</a>'+71 '<span class="github-text">ãFork </span>'+72 '<a class="forks" href="' + repoUrl + '/network/members" title="See forkers">?</a>'+73 '</div>'+74 '</div>'+75 '<div class="github-box-content">'+76 '<p class="description"><span></span> — <a href="' + repoUrl + '#readme">Read More</a></p>'+77 '<p class="link"></p>'+78 '</div>'+79 '<div class="github-box-download">'+80 '<div class="updated"></div>'+81 '<a class="download" href="' + repoUrl + '/zipball/master" title="Get repository">Download as zip</a>'+82 '</div>'+83 '</div>';84 _setHtml(repoEle, widget);85 _ajaxReq(repoEle, repo);86 }87 }88 }89 _appendCss();90 _init();91 window.GithubRepoWidget = {92 init: _init93 };...
Using AI Code Generation
1var TenSecondsMathGame = function (options) {2 this.operation = options.operation;3 this.numberLimit = options.numberLimit;4 this.time = options.time;5};6TenSecondsMathGame.prototype.start = function () {7 this.startTimer();8 this.generateQuestion();9 this.askQuestion();10};11TenSecondsMathGame.prototype.startTimer = function () {12 var self = this;13 this.timer = setInterval(function () {14 self.time--;15 if (self.time === 0) {16 console.log("Time's up!");17 clearInterval(self.timer);18 }19 }, 1000);20};21TenSecondsMathGame.prototype.generateQuestion = function () {22 var randomNumber1 = Math.floor(Math.random() * this.numberLimit);23 var randomNumber2 = Math.floor(Math.random() * this.numberLimit);24 var result;25 if (this.operation === "+") {26 result = randomNumber1 + randomNumber2;27 } else if (this.operation === "-") {28 result = randomNumber1 - randomNumber2;29 } else if (this.operation === "*") {30 result = randomNumber1 * randomNumber2;31 } else if (this.operation === "/") {32 result = randomNumber1 / randomNumber2;33 }34 this.question = randomNumber1 + " " + this.operation + " " + randomNumber2;35 this.result = result;36};37TenSecondsMathGame.prototype.askQuestion = function () {38 var self = this;39 this.questionInterval = setInterval(function () {40 console.log(self.question);41 }, 1000);42};43TenSecondsMathGame.prototype.checkAnswer = function (answer) {44 if (answer === this.result) {45 console.log("Correct!");46 } else {47 console.log("Wrong!");48 }49};50var game1 = new TenSecondsMathGame({51});52game1.start();
Using AI Code Generation
1var test4 = require('./test4module.js');2test4.test4module();3exports.test4module = function() {4 console.log('test4module');5};6var test5 = require('./test5module.js');7test5.test5module();8exports.test5module = function() {9 console.log('test5module');10};11var test6 = require('./test6module.js');12test6.test6module();13exports.test6module = function() {14 console.log('test6module');15};16var test7 = require('./test7module.js');17test7.test7module();18exports.test7module = function() {19 console.log('test7module');20};21var test8 = require('./test8module.js');22test8.test8module();23exports.test8module = function() {24 console.log('test8module');25};26var test9 = require('./test9module.js');27test9.test9module();28exports.test9module = function() {29 console.log('test9module');30};31var test10 = require('./test10module.js');32test10.test10module();33exports.test10module = function() {34 console.log('test10module');35};36var test11 = require('./test11module.js');
Using AI Code Generation
1const BestMatch = require('best-match');2const bestMatch = new BestMatch();3const test4 = require('./test4.json');4const test4Keys = Object.keys(test4);5const test4Values = Object.values(test4);6const test4KeysValues = Object.entries(test4);7const test4KeysValues2 = Object.entries(test4).map(function (e) {8return e[1];9});10const test4KeysValues3 = Object.entries(test4).map(function (e) {11return e[1].length;12});
Using AI Code Generation
1var BestFitLine = require('BestFitLine');2var x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];3var y = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];4var bfl = new BestFitLine(x, y);5console.log(bfl);6console.log(bfl.slope);7console.log(bfl.intercept);8console.log(bfl.rSquared);9var BestFitLine = require('BestFitLine');10var x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];11var y = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];12var bfl = new BestFitLine(x, y);13console.log(bfl);14console.log(bfl.slope);15console.log(bfl.intercept);16console.log(bfl.rSquared);17var BestFitLine = require('BestFitLine');18var x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!