{"action":"created","comment":{"url":"https://api.github.com/repos/jes708/CodeGenius/pulls/comments/68490676","id":68490676,"diff_hunk":"@@ -0,0 +1,196 @@\n+'use strict';\n+\n+//exports\n+module.exports = {\n+  appPath,\n+  dbPath,\n+  bluebirdForTests,\n+  createAdminUser,\n+  createGuest,\n+  createLocalUser,\n+  Credentials,\n+  db,\n+  describeIt,\n+  ensureAuthenticated,\n+  _err,\n+  forceSyncDb,\n+  getApp,\n+  getModel,\n+  getModels,\n+  joinRootPath,\n+  logInAgent,\n+  logOutAgent,\n+  respondWith404,\n+  responder,\n+  routerUse,\n+  Sequelize,\n+  should,\n+  supertest,\n+  syncDb\n+}\n+\n+\n+\n+// dependencies\n+const path = require( 'path' );\n+const bluebird = bluebirdForTests();\n+\n+//declarations\n+const appPath = joinRootPath( \"./server/app\" );\n+const dbPath = joinRootPath( \"./server/db\" );\n+global.paths = {routerUtils: joinRootPath( './server/app/routes/utils.js')}\n+\n+function addUser( credentials ) {\n+\n+  // console.log(credentials);\n+  return getModel('user').create( credentials )\n+  .then( result => {\n+    \n+  })\n+  .catch( err => console.log('oh no there was an error here!', err))\n+}\n+\n+function bluebirdForTests() {\n+\n+  const Bluebird = require( 'bluebird' );\n+  return Bluebird;\n+}\n+\n+function createAdminUser( userInfo ) {\n+  userInfo.isAdmin = true;\n+  return createLocalUser( userInfo )\n+}\n+\n+function createAgent( ) {\n+\n+  return supertest().agent( getApp() );\n+}\n+\n+function createGuest() {\n+  return createAgent();\n+}\n+\n+function createLocalUser( userInfo ) {\n+\n+  return addUser(userInfo).then( ()=> {\n+\n+    return createAgent()})\n+}\n+\n+function Credentials( username, password, email ) {\n+  return {\n+    username,\n+    password,\n+    email\n+  }\n+}\n+\n+function db() {\n+\n+  return require( dbPath )\n+}\n+\n+function describeIt( describeStmt, itStmt, callback = function(){}, callWithDone ){\n+  return describe( describeStmt, function() {\n+    it( itStmt, callback( callWithDone ? done : undefined ) )\n+  })\n+}\n+\n+function ensureAuthenticated(req, res, next) {\n+    if (req.isAuthenticated()) {\n+        next();\n+    } else {\n+        res.status(401).end();\n+    }\n+}\n+\n+function _err( err ) {\n+  return {\n+    err\n+  };\n+}\n+\n+function forceSyncDb(){\n+  return syncDb(true);\n+}\n+\n+function getApp() {\n+\n+  let theDb = db();\n+  let app = require( appPath )(theDb)\n+  return app;\n+}\n+\n+function getUserModel(){\n+  return require('./../../db/models/user')\n+}\n+\n+function getModel( model ) {\n+\n+  const _db = db();\n+  // console.dir(_db.models.user);\n+  return _db.models[model];\n+}\n+\n+function getModels( models ) {\n+  return models.map( model => getModel( model ) )\n+}\n+\n+function joinRootPath( targetPath ) {\n+  return path.join( './../../../', targetPath )\n+}\n+\n+function logInAgent( agent, userInfo ) {\n+  return agent\n+    .post( '/login' )\n+    .send( userInfo );\n+}\n+\n+function logOutAgent( agent ) {\n+  return agent.post( '/logout' )\n+}\n+function respondWith404(router){\n+  router.use(function (req, res) {\n+      res.status(404).end();\n+  });\n+}\n+\n+class responder {\n+  constructor(router){\n+    this.router = router;\n+  }\n+  with404(){\n+    respondWith404(this.router);\n+  }\n+}\n+\n+function routerUse(router){","path":"server/app/routes/utils.js","position":167,"original_position":167,"commit_id":"b217bf0ce8805d09c18b89df22f5d6e801659c73","original_commit_id":"b217bf0ce8805d09c18b89df22f5d6e801659c73","user":{"login":"jdhang","id":5394681,"avatar_url":"https://avatars.githubusercontent.com/u/5394681?v=3","gravatar_id":"","url":"https://api.github.com/users/jdhang","html_url":"https://github.com/jdhang","followers_url":"https://api.github.com/users/jdhang/followers","following_url":"https://api.github.com/users/jdhang/following{/other_user}","gists_url":"https://api.github.com/users/jdhang/gists{/gist_id}","starred_url":"https://api.github.com/users/jdhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdhang/subscriptions","organizations_url":"https://api.github.com/users/jdhang/orgs","repos_url":"https://api.github.com/users/jdhang/repos","events_url":"https://api.github.com/users/jdhang/events{/privacy}","received_events_url":"https://api.github.com/users/jdhang/received_events","type":"User","site_admin":false},"body":"Does this shorten the original syntax by much? @thejohnbackes ","created_at":"2016-06-25T16:42:21Z","updated_at":"2016-06-25T16:42:21Z","html_url":"https://github.com/jes708/CodeGenius/pull/38#discussion_r68490676","pull_request_url":"https://api.github.com/repos/jes708/CodeGenius/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/jes708/CodeGenius/pulls/comments/68490676"},"html":{"href":"https://github.com/jes708/CodeGenius/pull/38#discussion_r68490676"},"pull_request":{"href":"https://api.github.com/repos/jes708/CodeGenius/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/jes708/CodeGenius/pulls/38","id":75060580,"html_url":"https://github.com/jes708/CodeGenius/pull/38","diff_url":"https://github.com/jes708/CodeGenius/pull/38.diff","patch_url":"https://github.com/jes708/CodeGenius/pull/38.patch","issue_url":"https://api.github.com/repos/jes708/CodeGenius/issues/38","number":38,"state":"open","locked":false,"title":"utility library for API routes","user":{"login":"thejohnbackes","id":13596692,"avatar_url":"https://avatars.githubusercontent.com/u/13596692?v=3","gravatar_id":"","url":"https://api.github.com/users/thejohnbackes","html_url":"https://github.com/thejohnbackes","followers_url":"https://api.github.com/users/thejohnbackes/followers","following_url":"https://api.github.com/users/thejohnbackes/following{/other_user}","gists_url":"https://api.github.com/users/thejohnbackes/gists{/gist_id}","starred_url":"https://api.github.com/users/thejohnbackes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejohnbackes/subscriptions","organizations_url":"https://api.github.com/users/thejohnbackes/orgs","repos_url":"https://api.github.com/users/thejohnbackes/repos","events_url":"https://api.github.com/users/thejohnbackes/events{/privacy}","received_events_url":"https://api.github.com/users/thejohnbackes/received_events","type":"User","site_admin":false},"body":"I created this library because of challenges I had with stackstore API routes. the utils folder contains a number of shorthand methods to make routes and tests more syntactical and concise.","created_at":"2016-06-24T03:43:21Z","updated_at":"2016-06-25T16:42:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0349d8fcb6b23d5ad2daedb04a0ec200a2be34c6","assignee":{"login":"jdhang","id":5394681,"avatar_url":"https://avatars.githubusercontent.com/u/5394681?v=3","gravatar_id":"","url":"https://api.github.com/users/jdhang","html_url":"https://github.com/jdhang","followers_url":"https://api.github.com/users/jdhang/followers","following_url":"https://api.github.com/users/jdhang/following{/other_user}","gists_url":"https://api.github.com/users/jdhang/gists{/gist_id}","starred_url":"https://api.github.com/users/jdhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdhang/subscriptions","organizations_url":"https://api.github.com/users/jdhang/orgs","repos_url":"https://api.github.com/users/jdhang/repos","events_url":"https://api.github.com/users/jdhang/events{/privacy}","received_events_url":"https://api.github.com/users/jdhang/received_events","type":"User","site_admin":false},"assignees":[{"login":"jdhang","id":5394681,"avatar_url":"https://avatars.githubusercontent.com/u/5394681?v=3","gravatar_id":"","url":"https://api.github.com/users/jdhang","html_url":"https://github.com/jdhang","followers_url":"https://api.github.com/users/jdhang/followers","following_url":"https://api.github.com/users/jdhang/following{/other_user}","gists_url":"https://api.github.com/users/jdhang/gists{/gist_id}","starred_url":"https://api.github.com/users/jdhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdhang/subscriptions","organizations_url":"https://api.github.com/users/jdhang/orgs","repos_url":"https://api.github.com/users/jdhang/repos","events_url":"https://api.github.com/users/jdhang/events{/privacy}","received_events_url":"https://api.github.com/users/jdhang/received_events","type":"User","site_admin":false},{"login":"jes708","id":16601510,"avatar_url":"https://avatars.githubusercontent.com/u/16601510?v=3","gravatar_id":"","url":"https://api.github.com/users/jes708","html_url":"https://github.com/jes708","followers_url":"https://api.github.com/users/jes708/followers","following_url":"https://api.github.com/users/jes708/following{/other_user}","gists_url":"https://api.github.com/users/jes708/gists{/gist_id}","starred_url":"https://api.github.com/users/jes708/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jes708/subscriptions","organizations_url":"https://api.github.com/users/jes708/orgs","repos_url":"https://api.github.com/users/jes708/repos","events_url":"https://api.github.com/users/jes708/events{/privacy}","received_events_url":"https://api.github.com/users/jes708/received_events","type":"User","site_admin":false},{"login":"jancodes","id":16806234,"avatar_url":"https://avatars.githubusercontent.com/u/16806234?v=3","gravatar_id":"","url":"https://api.github.com/users/jancodes","html_url":"https://github.com/jancodes","followers_url":"https://api.github.com/users/jancodes/followers","following_url":"https://api.github.com/users/jancodes/following{/other_user}","gists_url":"https://api.github.com/users/jancodes/gists{/gist_id}","starred_url":"https://api.github.com/users/jancodes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jancodes/subscriptions","organizations_url":"https://api.github.com/users/jancodes/orgs","repos_url":"https://api.github.com/users/jancodes/repos","events_url":"https://api.github.com/users/jancodes/events{/privacy}","received_events_url":"https://api.github.com/users/jancodes/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/jes708/CodeGenius/pulls/38/commits","review_comments_url":"https://api.github.com/repos/jes708/CodeGenius/pulls/38/comments","review_comment_url":"https://api.github.com/repos/jes708/CodeGenius/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jes708/CodeGenius/issues/38/comments","statuses_url":"https://api.github.com/repos/jes708/CodeGenius/statuses/b217bf0ce8805d09c18b89df22f5d6e801659c73","head":{"label":"thejohnbackes:master","ref":"master","sha":"b217bf0ce8805d09c18b89df22f5d6e801659c73","user":{"login":"thejohnbackes","id":13596692,"avatar_url":"https://avatars.githubusercontent.com/u/13596692?v=3","gravatar_id":"","url":"https://api.github.com/users/thejohnbackes","html_url":"https://github.com/thejohnbackes","followers_url":"https://api.github.com/users/thejohnbackes/followers","following_url":"https://api.github.com/users/thejohnbackes/following{/other_user}","gists_url":"https://api.github.com/users/thejohnbackes/gists{/gist_id}","starred_url":"https://api.github.com/users/thejohnbackes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejohnbackes/subscriptions","organizations_url":"https://api.github.com/users/thejohnbackes/orgs","repos_url":"https://api.github.com/users/thejohnbackes/repos","events_url":"https://api.github.com/users/thejohnbackes/events{/privacy}","received_events_url":"https://api.github.com/users/thejohnbackes/received_events","type":"User","site_admin":false},"repo":{"id":61815070,"name":"CodeGenius","full_name":"thejohnbackes/CodeGenius","owner":{"login":"thejohnbackes","id":13596692,"avatar_url":"https://avatars.githubusercontent.com/u/13596692?v=3","gravatar_id":"","url":"https://api.github.com/users/thejohnbackes","html_url":"https://github.com/thejohnbackes","followers_url":"https://api.github.com/users/thejohnbackes/followers","following_url":"https://api.github.com/users/thejohnbackes/following{/other_user}","gists_url":"https://api.github.com/users/thejohnbackes/gists{/gist_id}","starred_url":"https://api.github.com/users/thejohnbackes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejohnbackes/subscriptions","organizations_url":"https://api.github.com/users/thejohnbackes/orgs","repos_url":"https://api.github.com/users/thejohnbackes/repos","events_url":"https://api.github.com/users/thejohnbackes/events{/privacy}","received_events_url":"https://api.github.com/users/thejohnbackes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/thejohnbackes/CodeGenius","description":"","fork":true,"url":"https://api.github.com/repos/thejohnbackes/CodeGenius","forks_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/forks","keys_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/teams","hooks_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/hooks","issue_events_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/issues/events{/number}","events_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/events","assignees_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/assignees{/user}","branches_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/branches{/branch}","tags_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/tags","blobs_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/git/refs{/sha}","trees_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/statuses/{sha}","languages_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/languages","stargazers_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/stargazers","contributors_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/contributors","subscribers_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/subscribers","subscription_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/subscription","commits_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/commits{/sha}","git_commits_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/git/commits{/sha}","comments_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/comments{/number}","issue_comment_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/issues/comments{/number}","contents_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/contents/{+path}","compare_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/merges","archive_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/downloads","issues_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/issues{/number}","pulls_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/pulls{/number}","milestones_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/milestones{/number}","notifications_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/labels{/name}","releases_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/releases{/id}","deployments_url":"https://api.github.com/repos/thejohnbackes/CodeGenius/deployments","created_at":"2016-06-23T15:14:20Z","updated_at":"2016-06-24T03:39:07Z","pushed_at":"2016-06-24T21:15:24Z","git_url":"git://github.com/thejohnbackes/CodeGenius.git","ssh_url":"git@github.com:thejohnbackes/CodeGenius.git","clone_url":"https://github.com/thejohnbackes/CodeGenius.git","svn_url":"https://github.com/thejohnbackes/CodeGenius","homepage":null,"size":18045,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jes708:master","ref":"master","sha":"5b27373c29bdfefb90fb151b2bad5f2e5c7505ce","user":{"login":"jes708","id":16601510,"avatar_url":"https://avatars.githubusercontent.com/u/16601510?v=3","gravatar_id":"","url":"https://api.github.com/users/jes708","html_url":"https://github.com/jes708","followers_url":"https://api.github.com/users/jes708/followers","following_url":"https://api.github.com/users/jes708/following{/other_user}","gists_url":"https://api.github.com/users/jes708/gists{/gist_id}","starred_url":"https://api.github.com/users/jes708/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jes708/subscriptions","organizations_url":"https://api.github.com/users/jes708/orgs","repos_url":"https://api.github.com/users/jes708/repos","events_url":"https://api.github.com/users/jes708/events{/privacy}","received_events_url":"https://api.github.com/users/jes708/received_events","type":"User","site_admin":false},"repo":{"id":61665508,"name":"CodeGenius","full_name":"jes708/CodeGenius","owner":{"login":"jes708","id":16601510,"avatar_url":"https://avatars.githubusercontent.com/u/16601510?v=3","gravatar_id":"","url":"https://api.github.com/users/jes708","html_url":"https://github.com/jes708","followers_url":"https://api.github.com/users/jes708/followers","following_url":"https://api.github.com/users/jes708/following{/other_user}","gists_url":"https://api.github.com/users/jes708/gists{/gist_id}","starred_url":"https://api.github.com/users/jes708/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jes708/subscriptions","organizations_url":"https://api.github.com/users/jes708/orgs","repos_url":"https://api.github.com/users/jes708/repos","events_url":"https://api.github.com/users/jes708/events{/privacy}","received_events_url":"https://api.github.com/users/jes708/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jes708/CodeGenius","description":"","fork":false,"url":"https://api.github.com/repos/jes708/CodeGenius","forks_url":"https://api.github.com/repos/jes708/CodeGenius/forks","keys_url":"https://api.github.com/repos/jes708/CodeGenius/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jes708/CodeGenius/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jes708/CodeGenius/teams","hooks_url":"https://api.github.com/repos/jes708/CodeGenius/hooks","issue_events_url":"https://api.github.com/repos/jes708/CodeGenius/issues/events{/number}","events_url":"https://api.github.com/repos/jes708/CodeGenius/events","assignees_url":"https://api.github.com/repos/jes708/CodeGenius/assignees{/user}","branches_url":"https://api.github.com/repos/jes708/CodeGenius/branches{/branch}","tags_url":"https://api.github.com/repos/jes708/CodeGenius/tags","blobs_url":"https://api.github.com/repos/jes708/CodeGenius/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jes708/CodeGenius/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jes708/CodeGenius/git/refs{/sha}","trees_url":"https://api.github.com/repos/jes708/CodeGenius/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jes708/CodeGenius/statuses/{sha}","languages_url":"https://api.github.com/repos/jes708/CodeGenius/languages","stargazers_url":"https://api.github.com/repos/jes708/CodeGenius/stargazers","contributors_url":"https://api.github.com/repos/jes708/CodeGenius/contributors","subscribers_url":"https://api.github.com/repos/jes708/CodeGenius/subscribers","subscription_url":"https://api.github.com/repos/jes708/CodeGenius/subscription","commits_url":"https://api.github.com/repos/jes708/CodeGenius/commits{/sha}","git_commits_url":"https://api.github.com/repos/jes708/CodeGenius/git/commits{/sha}","comments_url":"https://api.github.com/repos/jes708/CodeGenius/comments{/number}","issue_comment_url":"https://api.github.com/repos/jes708/CodeGenius/issues/comments{/number}","contents_url":"https://api.github.com/repos/jes708/CodeGenius/contents/{+path}","compare_url":"https://api.github.com/repos/jes708/CodeGenius/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jes708/CodeGenius/merges","archive_url":"https://api.github.com/repos/jes708/CodeGenius/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jes708/CodeGenius/downloads","issues_url":"https://api.github.com/repos/jes708/CodeGenius/issues{/number}","pulls_url":"https://api.github.com/repos/jes708/CodeGenius/pulls{/number}","milestones_url":"https://api.github.com/repos/jes708/CodeGenius/milestones{/number}","notifications_url":"https://api.github.com/repos/jes708/CodeGenius/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jes708/CodeGenius/labels{/name}","releases_url":"https://api.github.com/repos/jes708/CodeGenius/releases{/id}","deployments_url":"https://api.github.com/repos/jes708/CodeGenius/deployments","created_at":"2016-06-21T20:37:11Z","updated_at":"2016-06-23T20:55:02Z","pushed_at":"2016-06-25T16:37:15Z","git_url":"git://github.com/jes708/CodeGenius.git","ssh_url":"git@github.com:jes708/CodeGenius.git","clone_url":"https://github.com/jes708/CodeGenius.git","svn_url":"https://github.com/jes708/CodeGenius","homepage":null,"size":18072,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":33,"forks":2,"open_issues":33,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jes708/CodeGenius/pulls/38"},"html":{"href":"https://github.com/jes708/CodeGenius/pull/38"},"issue":{"href":"https://api.github.com/repos/jes708/CodeGenius/issues/38"},"comments":{"href":"https://api.github.com/repos/jes708/CodeGenius/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/jes708/CodeGenius/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/jes708/CodeGenius/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jes708/CodeGenius/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/jes708/CodeGenius/statuses/b217bf0ce8805d09c18b89df22f5d6e801659c73"}}}}
{"actor":{"display_login":"jdhang"}}