{"action":"created","comment":{"url":"https://api.github.com/repos/stockduel/stockduel/pulls/comments/47434976","id":47434976,"diff_hunk":"@@ -0,0 +1,158 @@\n+var chai = require('chai');\n+var expect = chai.expect;\n+var Promise = require('bluebird');\n+var knex = require('../index');\n+\n+var tradesController = require('../dbcontrollers/tradesController')(knex);\n+var matchesController = require('../dbcontrollers/matchesController')(knex);\n+\n+var users = [{\n+  username: 'annaUser',\n+  password: 'annaPassword',\n+  name: 'anna',\n+  email: 'anna@annar'\n+}, {\n+  username: 'kateUser',\n+  password: 'katePassword',\n+  name: 'kate',\n+  email: 'kate@kater'\n+}];\n+\n+var matches = [{\n+  startFunds: 100000,\n+  type: 'TEST'\n+}];\n+\n+var stock = {\n+  name: 'Facebook, Inc.',\n+  symbol: 'FB',\n+  industry: 'Computer Software: Programming, Data Processing',\n+  sector: 'Technology',\n+  exchange: 'NASDAQ'\n+};\n+\n+// ============= Setup ============= \\\\\n+before(function (done) {\n+  //insert users into DB\n+  knex('users').insert(users)\n+    .then(function () {\n+      return Promise.map(users, function (user) {\n+        return knex.select().table('users').where('email', user.email);\n+      });\n+    })\n+    //gets our user id\n+    .then(function (response) {\n+      users = response.map(function (user) {\n+        return user[0];\n+      });\n+    })\n+    //create a match\n+    .then(function () {\n+      var user = users[0];\n+      var match = matches[0];\n+      return matchesController.createMatch(user.u_id, match.startFunds, match.type);\n+    })\n+    .then(function (createdMatch) {\n+      matches[0].m_id = createdMatch.m_id;\n+      done();\n+    });\n+\n+});\n+\n+// ============= Teardown ============= \\\\\n+after(function (done) {\n+  //remove trades\n+  knex('trades').where({\n+      'match_id': matches[0].m_id\n+    }).del()\n+    //remove matches\n+    .then(function () {\n+      return Promise.map(matches, function (match) {\n+        return knex('matches').where('type', 'TEST').del();\n+      });\n+    })\n+    //remove users\n+    .then(function () {\n+      return Promise.map(users, function (user) {\n+        return knex('users').where('email', user.email).del();\n+      });\n+    })\n+    .then(function () {\n+      done();\n+    });\n+\n+});\n+\n+describe('Trade Controller', function () {\n+\n+  it('should be able to place a buy trade', function (done) {\n+    var user = users[0];\n+    var match = matches[0];\n+    var trade = {\n+      shares: 100,\n+      symbol: stock.symbol\n+    };\n+\n+    tradesController.buy(user.u_id, match.m_id, trade.shares, trade.symbol)\n+      .then(function (trade) {\n+        // console.log(trade);\n+        expect(trade.shares).to.equal(100);\n+        done();\n+      });\n+  });\n+\n+\n+\n+  // it('should reject a buy that the user cant afford', function () {\n+  //   return tradesController.buy(1,1,200000,'buy','TFSC')\n+  //   .then(function (data) {\n+  //     console.log('Should not be logged!',data);\n+  //   })\n+  //  .catch(function (err) {\n+  //    console.log(err);\n+  //  });\n+  // });\n+\n+  it('should be able to place a sell trade', function (done) {\n+    var user = users[0];\n+    var match = matches[0];\n+    var trade = {\n+      shares: 90,\n+      symbol: 'FB'\n+    };\n+\n+    tradesController.sell(user.u_id, match.m_id, trade.shares, trade.symbol)\n+      .then(function (trade) {\n+        // console.log('trade', trade);","path":"server/db/spec/tradesControllerSpec.js","position":126,"original_position":126,"commit_id":"bb4479c54bbce318ca644318500ffce65c12ad1f","original_commit_id":"bb4479c54bbce318ca644318500ffce65c12ad1f","user":{"login":"muddybarefeet","id":11532620,"avatar_url":"https://avatars.githubusercontent.com/u/11532620?v=3","gravatar_id":"","url":"https://api.github.com/users/muddybarefeet","html_url":"https://github.com/muddybarefeet","followers_url":"https://api.github.com/users/muddybarefeet/followers","following_url":"https://api.github.com/users/muddybarefeet/following{/other_user}","gists_url":"https://api.github.com/users/muddybarefeet/gists{/gist_id}","starred_url":"https://api.github.com/users/muddybarefeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muddybarefeet/subscriptions","organizations_url":"https://api.github.com/users/muddybarefeet/orgs","repos_url":"https://api.github.com/users/muddybarefeet/repos","events_url":"https://api.github.com/users/muddybarefeet/events{/privacy}","received_events_url":"https://api.github.com/users/muddybarefeet/received_events","type":"User","site_admin":false},"body":"Is there a duplicate naming of trade here? might be better to change one? ","created_at":"2015-12-12T18:25:54Z","updated_at":"2015-12-12T18:25:54Z","html_url":"https://github.com/stockduel/stockduel/pull/62#discussion_r47434976","pull_request_url":"https://api.github.com/repos/stockduel/stockduel/pulls/62","_links":{"self":{"href":"https://api.github.com/repos/stockduel/stockduel/pulls/comments/47434976"},"html":{"href":"https://github.com/stockduel/stockduel/pull/62#discussion_r47434976"},"pull_request":{"href":"https://api.github.com/repos/stockduel/stockduel/pulls/62"}}},"pull_request":{"url":"https://api.github.com/repos/stockduel/stockduel/pulls/62","id":53470044,"html_url":"https://github.com/stockduel/stockduel/pull/62","diff_url":"https://github.com/stockduel/stockduel/pull/62.diff","patch_url":"https://github.com/stockduel/stockduel/pull/62.patch","issue_url":"https://api.github.com/repos/stockduel/stockduel/issues/62","number":62,"state":"open","locked":false,"title":"add anna's controllers","user":{"login":"tatethurston","id":2958064,"avatar_url":"https://avatars.githubusercontent.com/u/2958064?v=3","gravatar_id":"","url":"https://api.github.com/users/tatethurston","html_url":"https://github.com/tatethurston","followers_url":"https://api.github.com/users/tatethurston/followers","following_url":"https://api.github.com/users/tatethurston/following{/other_user}","gists_url":"https://api.github.com/users/tatethurston/gists{/gist_id}","starred_url":"https://api.github.com/users/tatethurston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tatethurston/subscriptions","organizations_url":"https://api.github.com/users/tatethurston/orgs","repos_url":"https://api.github.com/users/tatethurston/repos","events_url":"https://api.github.com/users/tatethurston/events{/privacy}","received_events_url":"https://api.github.com/users/tatethurston/received_events","type":"User","site_admin":false},"body":"add user controller\r\n\r\nadd match controller\r\n\r\nadd trade controller","created_at":"2015-12-12T06:28:44Z","updated_at":"2015-12-12T18:25:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b3afffe769893e2b22e535c1efb0c6ae5d15b23","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stockduel/stockduel/pulls/62/commits","review_comments_url":"https://api.github.com/repos/stockduel/stockduel/pulls/62/comments","review_comment_url":"https://api.github.com/repos/stockduel/stockduel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stockduel/stockduel/issues/62/comments","statuses_url":"https://api.github.com/repos/stockduel/stockduel/statuses/bb4479c54bbce318ca644318500ffce65c12ad1f","head":{"label":"tatethurston:anna","ref":"anna","sha":"bb4479c54bbce318ca644318500ffce65c12ad1f","user":{"login":"tatethurston","id":2958064,"avatar_url":"https://avatars.githubusercontent.com/u/2958064?v=3","gravatar_id":"","url":"https://api.github.com/users/tatethurston","html_url":"https://github.com/tatethurston","followers_url":"https://api.github.com/users/tatethurston/followers","following_url":"https://api.github.com/users/tatethurston/following{/other_user}","gists_url":"https://api.github.com/users/tatethurston/gists{/gist_id}","starred_url":"https://api.github.com/users/tatethurston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tatethurston/subscriptions","organizations_url":"https://api.github.com/users/tatethurston/orgs","repos_url":"https://api.github.com/users/tatethurston/repos","events_url":"https://api.github.com/users/tatethurston/events{/privacy}","received_events_url":"https://api.github.com/users/tatethurston/received_events","type":"User","site_admin":false},"repo":{"id":47434505,"name":"stockduel","full_name":"tatethurston/stockduel","owner":{"login":"tatethurston","id":2958064,"avatar_url":"https://avatars.githubusercontent.com/u/2958064?v=3","gravatar_id":"","url":"https://api.github.com/users/tatethurston","html_url":"https://github.com/tatethurston","followers_url":"https://api.github.com/users/tatethurston/followers","following_url":"https://api.github.com/users/tatethurston/following{/other_user}","gists_url":"https://api.github.com/users/tatethurston/gists{/gist_id}","starred_url":"https://api.github.com/users/tatethurston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tatethurston/subscriptions","organizations_url":"https://api.github.com/users/tatethurston/orgs","repos_url":"https://api.github.com/users/tatethurston/repos","events_url":"https://api.github.com/users/tatethurston/events{/privacy}","received_events_url":"https://api.github.com/users/tatethurston/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tatethurston/stockduel","description":"social stock trading platform","fork":true,"url":"https://api.github.com/repos/tatethurston/stockduel","forks_url":"https://api.github.com/repos/tatethurston/stockduel/forks","keys_url":"https://api.github.com/repos/tatethurston/stockduel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tatethurston/stockduel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tatethurston/stockduel/teams","hooks_url":"https://api.github.com/repos/tatethurston/stockduel/hooks","issue_events_url":"https://api.github.com/repos/tatethurston/stockduel/issues/events{/number}","events_url":"https://api.github.com/repos/tatethurston/stockduel/events","assignees_url":"https://api.github.com/repos/tatethurston/stockduel/assignees{/user}","branches_url":"https://api.github.com/repos/tatethurston/stockduel/branches{/branch}","tags_url":"https://api.github.com/repos/tatethurston/stockduel/tags","blobs_url":"https://api.github.com/repos/tatethurston/stockduel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tatethurston/stockduel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tatethurston/stockduel/git/refs{/sha}","trees_url":"https://api.github.com/repos/tatethurston/stockduel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tatethurston/stockduel/statuses/{sha}","languages_url":"https://api.github.com/repos/tatethurston/stockduel/languages","stargazers_url":"https://api.github.com/repos/tatethurston/stockduel/stargazers","contributors_url":"https://api.github.com/repos/tatethurston/stockduel/contributors","subscribers_url":"https://api.github.com/repos/tatethurston/stockduel/subscribers","subscription_url":"https://api.github.com/repos/tatethurston/stockduel/subscription","commits_url":"https://api.github.com/repos/tatethurston/stockduel/commits{/sha}","git_commits_url":"https://api.github.com/repos/tatethurston/stockduel/git/commits{/sha}","comments_url":"https://api.github.com/repos/tatethurston/stockduel/comments{/number}","issue_comment_url":"https://api.github.com/repos/tatethurston/stockduel/issues/comments{/number}","contents_url":"https://api.github.com/repos/tatethurston/stockduel/contents/{+path}","compare_url":"https://api.github.com/repos/tatethurston/stockduel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tatethurston/stockduel/merges","archive_url":"https://api.github.com/repos/tatethurston/stockduel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tatethurston/stockduel/downloads","issues_url":"https://api.github.com/repos/tatethurston/stockduel/issues{/number}","pulls_url":"https://api.github.com/repos/tatethurston/stockduel/pulls{/number}","milestones_url":"https://api.github.com/repos/tatethurston/stockduel/milestones{/number}","notifications_url":"https://api.github.com/repos/tatethurston/stockduel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tatethurston/stockduel/labels{/name}","releases_url":"https://api.github.com/repos/tatethurston/stockduel/releases{/id}","created_at":"2015-12-04T23:46:46Z","updated_at":"2015-12-08T03:52:03Z","pushed_at":"2015-12-12T06:26:47Z","git_url":"git://github.com/tatethurston/stockduel.git","ssh_url":"git@github.com:tatethurston/stockduel.git","clone_url":"https://github.com/tatethurston/stockduel.git","svn_url":"https://github.com/tatethurston/stockduel","homepage":null,"size":788,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"stockduel:master","ref":"master","sha":"455c38e8df2864906a00f8a5e41989dc213269e1","user":{"login":"stockduel","id":16145620,"avatar_url":"https://avatars.githubusercontent.com/u/16145620?v=3","gravatar_id":"","url":"https://api.github.com/users/stockduel","html_url":"https://github.com/stockduel","followers_url":"https://api.github.com/users/stockduel/followers","following_url":"https://api.github.com/users/stockduel/following{/other_user}","gists_url":"https://api.github.com/users/stockduel/gists{/gist_id}","starred_url":"https://api.github.com/users/stockduel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stockduel/subscriptions","organizations_url":"https://api.github.com/users/stockduel/orgs","repos_url":"https://api.github.com/users/stockduel/repos","events_url":"https://api.github.com/users/stockduel/events{/privacy}","received_events_url":"https://api.github.com/users/stockduel/received_events","type":"Organization","site_admin":false},"repo":{"id":47378711,"name":"stockduel","full_name":"stockduel/stockduel","owner":{"login":"stockduel","id":16145620,"avatar_url":"https://avatars.githubusercontent.com/u/16145620?v=3","gravatar_id":"","url":"https://api.github.com/users/stockduel","html_url":"https://github.com/stockduel","followers_url":"https://api.github.com/users/stockduel/followers","following_url":"https://api.github.com/users/stockduel/following{/other_user}","gists_url":"https://api.github.com/users/stockduel/gists{/gist_id}","starred_url":"https://api.github.com/users/stockduel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stockduel/subscriptions","organizations_url":"https://api.github.com/users/stockduel/orgs","repos_url":"https://api.github.com/users/stockduel/repos","events_url":"https://api.github.com/users/stockduel/events{/privacy}","received_events_url":"https://api.github.com/users/stockduel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stockduel/stockduel","description":"social stock trading platform","fork":false,"url":"https://api.github.com/repos/stockduel/stockduel","forks_url":"https://api.github.com/repos/stockduel/stockduel/forks","keys_url":"https://api.github.com/repos/stockduel/stockduel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stockduel/stockduel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stockduel/stockduel/teams","hooks_url":"https://api.github.com/repos/stockduel/stockduel/hooks","issue_events_url":"https://api.github.com/repos/stockduel/stockduel/issues/events{/number}","events_url":"https://api.github.com/repos/stockduel/stockduel/events","assignees_url":"https://api.github.com/repos/stockduel/stockduel/assignees{/user}","branches_url":"https://api.github.com/repos/stockduel/stockduel/branches{/branch}","tags_url":"https://api.github.com/repos/stockduel/stockduel/tags","blobs_url":"https://api.github.com/repos/stockduel/stockduel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stockduel/stockduel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stockduel/stockduel/git/refs{/sha}","trees_url":"https://api.github.com/repos/stockduel/stockduel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stockduel/stockduel/statuses/{sha}","languages_url":"https://api.github.com/repos/stockduel/stockduel/languages","stargazers_url":"https://api.github.com/repos/stockduel/stockduel/stargazers","contributors_url":"https://api.github.com/repos/stockduel/stockduel/contributors","subscribers_url":"https://api.github.com/repos/stockduel/stockduel/subscribers","subscription_url":"https://api.github.com/repos/stockduel/stockduel/subscription","commits_url":"https://api.github.com/repos/stockduel/stockduel/commits{/sha}","git_commits_url":"https://api.github.com/repos/stockduel/stockduel/git/commits{/sha}","comments_url":"https://api.github.com/repos/stockduel/stockduel/comments{/number}","issue_comment_url":"https://api.github.com/repos/stockduel/stockduel/issues/comments{/number}","contents_url":"https://api.github.com/repos/stockduel/stockduel/contents/{+path}","compare_url":"https://api.github.com/repos/stockduel/stockduel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stockduel/stockduel/merges","archive_url":"https://api.github.com/repos/stockduel/stockduel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stockduel/stockduel/downloads","issues_url":"https://api.github.com/repos/stockduel/stockduel/issues{/number}","pulls_url":"https://api.github.com/repos/stockduel/stockduel/pulls{/number}","milestones_url":"https://api.github.com/repos/stockduel/stockduel/milestones{/number}","notifications_url":"https://api.github.com/repos/stockduel/stockduel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stockduel/stockduel/labels{/name}","releases_url":"https://api.github.com/repos/stockduel/stockduel/releases{/id}","created_at":"2015-12-04T03:29:44Z","updated_at":"2015-12-05T00:39:34Z","pushed_at":"2015-12-12T06:28:44Z","git_url":"git://github.com/stockduel/stockduel.git","ssh_url":"git@github.com:stockduel/stockduel.git","clone_url":"https://github.com/stockduel/stockduel.git","svn_url":"https://github.com/stockduel/stockduel","homepage":null,"size":809,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":17,"forks":5,"open_issues":17,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stockduel/stockduel/pulls/62"},"html":{"href":"https://github.com/stockduel/stockduel/pull/62"},"issue":{"href":"https://api.github.com/repos/stockduel/stockduel/issues/62"},"comments":{"href":"https://api.github.com/repos/stockduel/stockduel/issues/62/comments"},"review_comments":{"href":"https://api.github.com/repos/stockduel/stockduel/pulls/62/comments"},"review_comment":{"href":"https://api.github.com/repos/stockduel/stockduel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stockduel/stockduel/pulls/62/commits"},"statuses":{"href":"https://api.github.com/repos/stockduel/stockduel/statuses/bb4479c54bbce318ca644318500ffce65c12ad1f"}}}}