{"action":"created","comment":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments/57556177","id":57556177,"diff_hunk":"@@ -0,0 +1,185 @@\n+/* eslint-disable no-shadow */\n+import scoreTask from '../../../common/script/ops/scoreTask';\n+import {\n+  generateUser,\n+  generateDaily,\n+  generateHabit,\n+  generateTodo,\n+  generateReward,\n+} from '../../helpers/api-integration/v3';\n+import common from '../../../common';\n+\n+let EPSILON = 0.0001; // negligible distance between datapoints\n+\n+/* Helper Functions */\n+let rewrapUser = (user) => {\n+  user._wrapped = false;\n+  common.wrap(user);\n+  return user;\n+};\n+\n+let beforeAfter = async () => {\n+  let before = await generateUser();\n+  let after = _.cloneDeep(before);\n+  rewrapUser(after);\n+\n+  return {\n+    before,\n+    after,\n+  };\n+};\n+\n+let expectGainedPoints = (before, after, beforeTask, afterTask) => {\n+  expect(after.stats.hp).to.eql(50);\n+  expect(after.stats.exp).to.be.greaterThan(before.stats.exp);\n+  expect(after.stats.gp).to.be.greaterThan(before.stats.gp);\n+  expect(afterTask.value).to.be.greaterThan(beforeTask.value);\n+  if (afterTask.type === 'habit') {\n+    expect(afterTask.history).to.have.length(1);\n+  }\n+};\n+\n+let expectClosePoints = (before, after, beforeTask, task) => {\n+  expect(Math.abs(after.stats.exp - before.stats.exp)).to.be.lessThan(EPSILON);\n+  expect(Math.abs(after.stats.gp - before.stats.gp)).to.be.lessThan(EPSILON);\n+  expect(Math.abs(task.value - beforeTask.value)).to.be.lessThan(EPSILON);\n+};\n+\n+let _expectRoughlyEqualDates = (date1, date2) => {\n+  expect(date1.toString()).to.eql(date2.toString());\n+};\n+\n+describe('shared.ops.scoreTask', () => {\n+  let ref;\n+\n+  beforeEach(async () => {\n+    ref = await beforeAfter();\n+  });\n+\n+  it('throws error not enough gold', async () => {\n+    let reward = await generateReward({ userId: ref.after._id, text: 'some reward', value: 100 });\n+    expect(scoreTask.bind(_, { user: ref.after, task: reward })).to.throw('NotAuthorized: Not Enough Gold');","path":"test/common/ops/scoreTask.test.js","position":61,"original_position":61,"commit_id":"099cac6946b5b659288bf4638c40477b2d07b5cf","original_commit_id":"099cac6946b5b659288bf4638c40477b2d07b5cf","user":{"login":"paglias","id":589911,"avatar_url":"https://avatars.githubusercontent.com/u/589911?v=3","gravatar_id":"","url":"https://api.github.com/users/paglias","html_url":"https://github.com/paglias","followers_url":"https://api.github.com/users/paglias/followers","following_url":"https://api.github.com/users/paglias/following{/other_user}","gists_url":"https://api.github.com/users/paglias/gists{/gist_id}","starred_url":"https://api.github.com/users/paglias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paglias/subscriptions","organizations_url":"https://api.github.com/users/paglias/orgs","repos_url":"https://api.github.com/users/paglias/repos","events_url":"https://api.github.com/users/paglias/events{/privacy}","received_events_url":"https://api.github.com/users/paglias/received_events","type":"User","site_admin":false},"body":"you should use i18n.t like here https://github.com/HabitRPG/habitrpg/blob/api-v3/test/common/ops/allocate.js#L6.\r\n\r\nAlso why you're binding to `_`? When testing for an error you want to do like here https://github.com/HabitRPG/habitrpg/blob/api-v3/test/common/ops/allocate.js#L19\r\n\r\nexpect().to.throw is a bit confusing (you can read more here http://chaijs.com/api/bdd/#method_throw), you should pass a function (without executing it) and then expect.js will run it and see if it throws, so we used try/catch instead ","created_at":"2016-03-28T09:03:22Z","updated_at":"2016-03-28T09:03:22Z","html_url":"https://github.com/HabitRPG/habitrpg/pull/6962#discussion_r57556177","pull_request_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962","_links":{"self":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments/57556177"},"html":{"href":"https://github.com/HabitRPG/habitrpg/pull/6962#discussion_r57556177"},"pull_request":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962"}}},"pull_request":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962","id":64222868,"html_url":"https://github.com/HabitRPG/habitrpg/pull/6962","diff_url":"https://github.com/HabitRPG/habitrpg/pull/6962.diff","patch_url":"https://github.com/HabitRPG/habitrpg/pull/6962.patch","issue_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/6962","number":6962,"state":"open","locked":false,"title":"shared-code-user-score-task","user":{"login":"piousbox","id":831744,"avatar_url":"https://avatars.githubusercontent.com/u/831744?v=3","gravatar_id":"","url":"https://api.github.com/users/piousbox","html_url":"https://github.com/piousbox","followers_url":"https://api.github.com/users/piousbox/followers","following_url":"https://api.github.com/users/piousbox/following{/other_user}","gists_url":"https://api.github.com/users/piousbox/gists{/gist_id}","starred_url":"https://api.github.com/users/piousbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/piousbox/subscriptions","organizations_url":"https://api.github.com/users/piousbox/orgs","repos_url":"https://api.github.com/users/piousbox/repos","events_url":"https://api.github.com/users/piousbox/events{/privacy}","received_events_url":"https://api.github.com/users/piousbox/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-26T00:45:28Z","updated_at":"2016-03-28T09:03:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d39896bbef3daaeb8b1c0bce182735e4eaa8b6c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962/commits","review_comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962/comments","review_comment_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/6962/comments","statuses_url":"https://api.github.com/repos/HabitRPG/habitrpg/statuses/099cac6946b5b659288bf4638c40477b2d07b5cf","head":{"label":"piousbox:shared-code-user-score-task","ref":"shared-code-user-score-task","sha":"099cac6946b5b659288bf4638c40477b2d07b5cf","user":{"login":"piousbox","id":831744,"avatar_url":"https://avatars.githubusercontent.com/u/831744?v=3","gravatar_id":"","url":"https://api.github.com/users/piousbox","html_url":"https://github.com/piousbox","followers_url":"https://api.github.com/users/piousbox/followers","following_url":"https://api.github.com/users/piousbox/following{/other_user}","gists_url":"https://api.github.com/users/piousbox/gists{/gist_id}","starred_url":"https://api.github.com/users/piousbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/piousbox/subscriptions","organizations_url":"https://api.github.com/users/piousbox/orgs","repos_url":"https://api.github.com/users/piousbox/repos","events_url":"https://api.github.com/users/piousbox/events{/privacy}","received_events_url":"https://api.github.com/users/piousbox/received_events","type":"User","site_admin":false},"repo":{"id":52387429,"name":"habitrpg","full_name":"piousbox/habitrpg","owner":{"login":"piousbox","id":831744,"avatar_url":"https://avatars.githubusercontent.com/u/831744?v=3","gravatar_id":"","url":"https://api.github.com/users/piousbox","html_url":"https://github.com/piousbox","followers_url":"https://api.github.com/users/piousbox/followers","following_url":"https://api.github.com/users/piousbox/following{/other_user}","gists_url":"https://api.github.com/users/piousbox/gists{/gist_id}","starred_url":"https://api.github.com/users/piousbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/piousbox/subscriptions","organizations_url":"https://api.github.com/users/piousbox/orgs","repos_url":"https://api.github.com/users/piousbox/repos","events_url":"https://api.github.com/users/piousbox/events{/privacy}","received_events_url":"https://api.github.com/users/piousbox/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/piousbox/habitrpg","description":"A habit tracker app which treats your goals like a Role Playing Game.","fork":true,"url":"https://api.github.com/repos/piousbox/habitrpg","forks_url":"https://api.github.com/repos/piousbox/habitrpg/forks","keys_url":"https://api.github.com/repos/piousbox/habitrpg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/piousbox/habitrpg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/piousbox/habitrpg/teams","hooks_url":"https://api.github.com/repos/piousbox/habitrpg/hooks","issue_events_url":"https://api.github.com/repos/piousbox/habitrpg/issues/events{/number}","events_url":"https://api.github.com/repos/piousbox/habitrpg/events","assignees_url":"https://api.github.com/repos/piousbox/habitrpg/assignees{/user}","branches_url":"https://api.github.com/repos/piousbox/habitrpg/branches{/branch}","tags_url":"https://api.github.com/repos/piousbox/habitrpg/tags","blobs_url":"https://api.github.com/repos/piousbox/habitrpg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/piousbox/habitrpg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/piousbox/habitrpg/git/refs{/sha}","trees_url":"https://api.github.com/repos/piousbox/habitrpg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/piousbox/habitrpg/statuses/{sha}","languages_url":"https://api.github.com/repos/piousbox/habitrpg/languages","stargazers_url":"https://api.github.com/repos/piousbox/habitrpg/stargazers","contributors_url":"https://api.github.com/repos/piousbox/habitrpg/contributors","subscribers_url":"https://api.github.com/repos/piousbox/habitrpg/subscribers","subscription_url":"https://api.github.com/repos/piousbox/habitrpg/subscription","commits_url":"https://api.github.com/repos/piousbox/habitrpg/commits{/sha}","git_commits_url":"https://api.github.com/repos/piousbox/habitrpg/git/commits{/sha}","comments_url":"https://api.github.com/repos/piousbox/habitrpg/comments{/number}","issue_comment_url":"https://api.github.com/repos/piousbox/habitrpg/issues/comments{/number}","contents_url":"https://api.github.com/repos/piousbox/habitrpg/contents/{+path}","compare_url":"https://api.github.com/repos/piousbox/habitrpg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/piousbox/habitrpg/merges","archive_url":"https://api.github.com/repos/piousbox/habitrpg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/piousbox/habitrpg/downloads","issues_url":"https://api.github.com/repos/piousbox/habitrpg/issues{/number}","pulls_url":"https://api.github.com/repos/piousbox/habitrpg/pulls{/number}","milestones_url":"https://api.github.com/repos/piousbox/habitrpg/milestones{/number}","notifications_url":"https://api.github.com/repos/piousbox/habitrpg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/piousbox/habitrpg/labels{/name}","releases_url":"https://api.github.com/repos/piousbox/habitrpg/releases{/id}","deployments_url":"https://api.github.com/repos/piousbox/habitrpg/deployments","created_at":"2016-02-23T19:57:41Z","updated_at":"2016-02-23T19:57:49Z","pushed_at":"2016-03-28T03:35:07Z","git_url":"git://github.com/piousbox/habitrpg.git","ssh_url":"git@github.com:piousbox/habitrpg.git","clone_url":"https://github.com/piousbox/habitrpg.git","svn_url":"https://github.com/piousbox/habitrpg","homepage":"https://habitica.com","size":352324,"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":"develop"}},"base":{"label":"HabitRPG:api-v3","ref":"api-v3","sha":"1112d93b15f9118e9bf41c470aa35bf5011e3f80","user":{"login":"HabitRPG","id":3834775,"avatar_url":"https://avatars.githubusercontent.com/u/3834775?v=3","gravatar_id":"","url":"https://api.github.com/users/HabitRPG","html_url":"https://github.com/HabitRPG","followers_url":"https://api.github.com/users/HabitRPG/followers","following_url":"https://api.github.com/users/HabitRPG/following{/other_user}","gists_url":"https://api.github.com/users/HabitRPG/gists{/gist_id}","starred_url":"https://api.github.com/users/HabitRPG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HabitRPG/subscriptions","organizations_url":"https://api.github.com/users/HabitRPG/orgs","repos_url":"https://api.github.com/users/HabitRPG/repos","events_url":"https://api.github.com/users/HabitRPG/events{/privacy}","received_events_url":"https://api.github.com/users/HabitRPG/received_events","type":"Organization","site_admin":false},"repo":{"id":4578898,"name":"habitrpg","full_name":"HabitRPG/habitrpg","owner":{"login":"HabitRPG","id":3834775,"avatar_url":"https://avatars.githubusercontent.com/u/3834775?v=3","gravatar_id":"","url":"https://api.github.com/users/HabitRPG","html_url":"https://github.com/HabitRPG","followers_url":"https://api.github.com/users/HabitRPG/followers","following_url":"https://api.github.com/users/HabitRPG/following{/other_user}","gists_url":"https://api.github.com/users/HabitRPG/gists{/gist_id}","starred_url":"https://api.github.com/users/HabitRPG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HabitRPG/subscriptions","organizations_url":"https://api.github.com/users/HabitRPG/orgs","repos_url":"https://api.github.com/users/HabitRPG/repos","events_url":"https://api.github.com/users/HabitRPG/events{/privacy}","received_events_url":"https://api.github.com/users/HabitRPG/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HabitRPG/habitrpg","description":"A habit tracker app which treats your goals like a Role Playing Game.","fork":false,"url":"https://api.github.com/repos/HabitRPG/habitrpg","forks_url":"https://api.github.com/repos/HabitRPG/habitrpg/forks","keys_url":"https://api.github.com/repos/HabitRPG/habitrpg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HabitRPG/habitrpg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HabitRPG/habitrpg/teams","hooks_url":"https://api.github.com/repos/HabitRPG/habitrpg/hooks","issue_events_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/events{/number}","events_url":"https://api.github.com/repos/HabitRPG/habitrpg/events","assignees_url":"https://api.github.com/repos/HabitRPG/habitrpg/assignees{/user}","branches_url":"https://api.github.com/repos/HabitRPG/habitrpg/branches{/branch}","tags_url":"https://api.github.com/repos/HabitRPG/habitrpg/tags","blobs_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/refs{/sha}","trees_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HabitRPG/habitrpg/statuses/{sha}","languages_url":"https://api.github.com/repos/HabitRPG/habitrpg/languages","stargazers_url":"https://api.github.com/repos/HabitRPG/habitrpg/stargazers","contributors_url":"https://api.github.com/repos/HabitRPG/habitrpg/contributors","subscribers_url":"https://api.github.com/repos/HabitRPG/habitrpg/subscribers","subscription_url":"https://api.github.com/repos/HabitRPG/habitrpg/subscription","commits_url":"https://api.github.com/repos/HabitRPG/habitrpg/commits{/sha}","git_commits_url":"https://api.github.com/repos/HabitRPG/habitrpg/git/commits{/sha}","comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/comments{/number}","issue_comment_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/comments{/number}","contents_url":"https://api.github.com/repos/HabitRPG/habitrpg/contents/{+path}","compare_url":"https://api.github.com/repos/HabitRPG/habitrpg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HabitRPG/habitrpg/merges","archive_url":"https://api.github.com/repos/HabitRPG/habitrpg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HabitRPG/habitrpg/downloads","issues_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues{/number}","pulls_url":"https://api.github.com/repos/HabitRPG/habitrpg/pulls{/number}","milestones_url":"https://api.github.com/repos/HabitRPG/habitrpg/milestones{/number}","notifications_url":"https://api.github.com/repos/HabitRPG/habitrpg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HabitRPG/habitrpg/labels{/name}","releases_url":"https://api.github.com/repos/HabitRPG/habitrpg/releases{/id}","deployments_url":"https://api.github.com/repos/HabitRPG/habitrpg/deployments","created_at":"2012-06-06T22:49:48Z","updated_at":"2016-03-28T08:48:43Z","pushed_at":"2016-03-28T03:35:08Z","git_url":"git://github.com/HabitRPG/habitrpg.git","ssh_url":"git@github.com:HabitRPG/habitrpg.git","clone_url":"https://github.com/HabitRPG/habitrpg.git","svn_url":"https://github.com/HabitRPG/habitrpg","homepage":"https://habitica.com","size":367713,"stargazers_count":3689,"watchers_count":3689,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1528,"mirror_url":null,"open_issues_count":483,"forks":1528,"open_issues":483,"watchers":3689,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962"},"html":{"href":"https://github.com/HabitRPG/habitrpg/pull/6962"},"issue":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/issues/6962"},"comments":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/issues/6962/comments"},"review_comments":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962/comments"},"review_comment":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/pulls/6962/commits"},"statuses":{"href":"https://api.github.com/repos/HabitRPG/habitrpg/statuses/099cac6946b5b659288bf4638c40477b2d07b5cf"}}}}