{"action":"created","comment":{"url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/comments/131553285","pull_request_review_id":54544221,"id":131553285,"diff_hunk":"@@ -0,0 +1,114 @@\n+require('require-self-ref')\n+const test = require('ava')\n+const sinon = require('sinon')\n+const proxyquire = require('proxyquire')\n+const MockProducer = require('~/test/mocks/mockProducer')\n+const MockChangesStream = require('~/test/mocks/mockChangesStream')\n+const Promise = require('bluebird')\n+proxyquire.noPreserveCache()\n+\n+function makeProducerAndStubs (sandbox) {\n+  const createProducerStub = sandbox.stub()\n+  const publisher = proxyquire('~/src/UpdatesPublisher', {\n+    'windbreaker-service-util/queue': {\n+      createProducer: createProducerStub\n+    }\n+  })\n+  return {\n+    createProducerStub: createProducerStub,\n+    publisher: publisher\n+  }\n+}\n+\n+test.beforeEach('setup mock channel and connections', (t) => {\n+  const producerOptions = {\n+    queueName: 'test-queue'\n+  }\n+\n+  const sandbox = sinon.sandbox.create()\n+  const {publisher, createProducerStub} = makeProducerAndStubs(sandbox)\n+\n+  t.context = {\n+    producerOptions,\n+    sandbox,\n+    publisher,\n+    createProducerStub\n+  }\n+})\n+\n+test.afterEach('clean up', (t) => {\n+  const { sandbox } = t.context\n+\n+  sandbox.restore()\n+})\n+\n+test.serial('#setupProducer', async (t) => {\n+  const {producerOptions, createProducerStub, publisher} = t.context\n+  publisher.configure(producerOptions, 'http://unhappypath.sad', 'http://unhappierpath.sad', console)\n+  createProducerStub.onFirstCall().returns(Promise.reject(new Error('expected rejection')))\n+  createProducerStub.onSecondCall().returns(Promise.resolve())\n+  await publisher.setupProducer()\n+  t.true(createProducerStub.calledTwice)\n+})\n+test.serial('#setupChanges', async (t) => {\n+  const {producerOptions, sandbox, publisher} = t.context\n+  publisher.configure(producerOptions, 'http://unhappypath.sad', 'http://unhappierpath.sad', console)\n+  const consoleSpy = sandbox.spy(console, 'info')\n+  await publisher.setupChanges()\n+  t.true(consoleSpy.calledWith('changes stream successfully created'))\n+  publisher.changes.destroy()\n+})\n+test.serial('#start', async (t) => {\n+  // setup all mocks and context\n+  const {producerOptions, sandbox, publisher} = t.context\n+  publisher.configure(producerOptions, 'http://unhappypath.sad', 'http://unhappierpath.sad', console)\n+  publisher.producer = new MockProducer()\n+  publisher.changes = new MockChangesStream()\n+  // stubbing creation methods\n+  const setupProducerStub = sandbox.stub(publisher, 'setupProducer')\n+  const setupChangesStub = sandbox.stub(publisher, 'setupChanges')\n+  setupProducerStub.resolves()\n+  setupChangesStub.resolves()\n+  // spying mocks' methods\n+  const producerStopSpy = sandbox.spy(publisher.producer, 'stop')\n+  const changesDestroySpy = sandbox.spy(publisher.changes, 'destroy')\n+  // launch the publisher event loop\n+  publisher.start()\n+  t.true(setupProducerStub.notCalled)\n+  t.true(setupChangesStub.notCalled)\n+  // first producer fails\n+  publisher.producer.emitError()\n+  await Promise.delay(1100)\n+  t.true(producerStopSpy.calledOnce)\n+  t.true(changesDestroySpy.calledOnce)\n+  t.true(setupChangesStub.calledOnce)\n+  t.true(setupProducerStub.calledOnce)\n+  // then changes fails\n+  publisher.changes.emitError()\n+  await Promise.delay(1100)\n+  t.true(producerStopSpy.calledOnce) // i.e not called\n+  t.true(setupProducerStub.calledOnce) // ^\n+  console.log(changesDestroySpy.callCount)\n+  t.true(changesDestroySpy.callCount > 1)\n+  t.true(setupChangesStub.callCount > 1)\n+  // finally changes detects changes\n+  const producerSendMessageSpy = sandbox.spy(publisher.producer, 'sendMessage')\n+  publisher.changes.emitData()\n+  await Promise.delay(100)\n+  t.true(producerSendMessageSpy.calledWith({}))\n+})\n+\n+test.serial('#stop', async (t) => {\n+  const {producerOptions, sandbox, publisher} = t.context\n+  publisher.configure(producerOptions, 'http://unhappypath.sad', 'http://unhappierpath.sad', console)\n+  publisher.producer = new MockProducer()\n+  publisher.changes = new MockChangesStream()\n+  const producerStopSpy = sandbox.spy(publisher.producer, 'stop')\n+  const changesDestroySpy = sandbox.spy(publisher.changes, 'destroy')\n+  publisher.start()\n+  t.true(producerStopSpy.notCalled)\n+  t.true(changesDestroySpy.notCalled)\n+  await publisher.stop()\n+  t.true(producerStopSpy.calledOnce)\n+  t.true(changesDestroySpy.calledOnce)\n+})","path":"test/unit/UpdatesPublisherTest.js","position":114,"original_position":114,"commit_id":"efe00e5a4fc55c8c768536f2895dd1b911867f5f","original_commit_id":"efe00e5a4fc55c8c768536f2895dd1b911867f5f","user":{"login":"charlieduong94","id":9613701,"avatar_url":"https://avatars3.githubusercontent.com/u/9613701?v=4","gravatar_id":"","url":"https://api.github.com/users/charlieduong94","html_url":"https://github.com/charlieduong94","followers_url":"https://api.github.com/users/charlieduong94/followers","following_url":"https://api.github.com/users/charlieduong94/following{/other_user}","gists_url":"https://api.github.com/users/charlieduong94/gists{/gist_id}","starred_url":"https://api.github.com/users/charlieduong94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charlieduong94/subscriptions","organizations_url":"https://api.github.com/users/charlieduong94/orgs","repos_url":"https://api.github.com/users/charlieduong94/repos","events_url":"https://api.github.com/users/charlieduong94/events{/privacy}","received_events_url":"https://api.github.com/users/charlieduong94/received_events","type":"User","site_admin":false},"body":"Some spacing in between major parts of these tests would help a lot with readability/maintainability. You had good comments in the test above this one, but the others are lacking some comments that would make them easier to follow.","created_at":"2017-08-06T21:49:09Z","updated_at":"2017-08-06T22:00:52Z","html_url":"https://github.com/windbreaker-io/npm-watcher/pull/3#discussion_r131553285","pull_request_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/comments/131553285"},"html":{"href":"https://github.com/windbreaker-io/npm-watcher/pull/3#discussion_r131553285"},"pull_request":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3","id":134337482,"html_url":"https://github.com/windbreaker-io/npm-watcher/pull/3","diff_url":"https://github.com/windbreaker-io/npm-watcher/pull/3.diff","patch_url":"https://github.com/windbreaker-io/npm-watcher/pull/3.patch","issue_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/3","number":3,"state":"open","locked":false,"title":"V1","user":{"login":"mdaum","id":6503330,"avatar_url":"https://avatars0.githubusercontent.com/u/6503330?v=4","gravatar_id":"","url":"https://api.github.com/users/mdaum","html_url":"https://github.com/mdaum","followers_url":"https://api.github.com/users/mdaum/followers","following_url":"https://api.github.com/users/mdaum/following{/other_user}","gists_url":"https://api.github.com/users/mdaum/gists{/gist_id}","starred_url":"https://api.github.com/users/mdaum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdaum/subscriptions","organizations_url":"https://api.github.com/users/mdaum/orgs","repos_url":"https://api.github.com/users/mdaum/repos","events_url":"https://api.github.com/users/mdaum/events{/privacy}","received_events_url":"https://api.github.com/users/mdaum/received_events","type":"User","site_admin":false},"body":"first pass at npm watcher with tests...still have yet to add integration tests in which changes stream and/or producer fail...to make sure npmWatcher can recover...but this case is covered in unit tests w/ mocks","created_at":"2017-08-06T19:24:05Z","updated_at":"2017-08-06T22:00:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02ea9a138b4cb164a86c6d8e47f3eb8e0786c2c5","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3/commits","review_comments_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3/comments","review_comment_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/comments{/number}","comments_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/3/comments","statuses_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/statuses/efe00e5a4fc55c8c768536f2895dd1b911867f5f","head":{"label":"windbreaker-io:v1","ref":"v1","sha":"efe00e5a4fc55c8c768536f2895dd1b911867f5f","user":{"login":"windbreaker-io","id":29463585,"avatar_url":"https://avatars3.githubusercontent.com/u/29463585?v=4","gravatar_id":"","url":"https://api.github.com/users/windbreaker-io","html_url":"https://github.com/windbreaker-io","followers_url":"https://api.github.com/users/windbreaker-io/followers","following_url":"https://api.github.com/users/windbreaker-io/following{/other_user}","gists_url":"https://api.github.com/users/windbreaker-io/gists{/gist_id}","starred_url":"https://api.github.com/users/windbreaker-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windbreaker-io/subscriptions","organizations_url":"https://api.github.com/users/windbreaker-io/orgs","repos_url":"https://api.github.com/users/windbreaker-io/repos","events_url":"https://api.github.com/users/windbreaker-io/events{/privacy}","received_events_url":"https://api.github.com/users/windbreaker-io/received_events","type":"Organization","site_admin":false},"repo":{"id":95166245,"name":"npm-watcher","full_name":"windbreaker-io/npm-watcher","owner":{"login":"windbreaker-io","id":29463585,"avatar_url":"https://avatars3.githubusercontent.com/u/29463585?v=4","gravatar_id":"","url":"https://api.github.com/users/windbreaker-io","html_url":"https://github.com/windbreaker-io","followers_url":"https://api.github.com/users/windbreaker-io/followers","following_url":"https://api.github.com/users/windbreaker-io/following{/other_user}","gists_url":"https://api.github.com/users/windbreaker-io/gists{/gist_id}","starred_url":"https://api.github.com/users/windbreaker-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windbreaker-io/subscriptions","organizations_url":"https://api.github.com/users/windbreaker-io/orgs","repos_url":"https://api.github.com/users/windbreaker-io/repos","events_url":"https://api.github.com/users/windbreaker-io/events{/privacy}","received_events_url":"https://api.github.com/users/windbreaker-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/windbreaker-io/npm-watcher","description":"Follow npm registry and pass rabbitmq-compatible changes along to windbreaker","fork":false,"url":"https://api.github.com/repos/windbreaker-io/npm-watcher","forks_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/forks","keys_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/teams","hooks_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/hooks","issue_events_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/events{/number}","events_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/events","assignees_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/assignees{/user}","branches_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/branches{/branch}","tags_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/tags","blobs_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/refs{/sha}","trees_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/statuses/{sha}","languages_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/languages","stargazers_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/stargazers","contributors_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/contributors","subscribers_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/subscribers","subscription_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/subscription","commits_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/commits{/sha}","git_commits_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/commits{/sha}","comments_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/comments{/number}","issue_comment_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/comments{/number}","contents_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/contents/{+path}","compare_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/merges","archive_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/downloads","issues_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues{/number}","pulls_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls{/number}","milestones_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/milestones{/number}","notifications_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/labels{/name}","releases_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/releases{/id}","deployments_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/deployments","created_at":"2017-06-22T23:56:25Z","updated_at":"2017-06-24T20:29:41Z","pushed_at":"2017-08-06T20:10:00Z","git_url":"git://github.com/windbreaker-io/npm-watcher.git","ssh_url":"git@github.com:windbreaker-io/npm-watcher.git","clone_url":"https://github.com/windbreaker-io/npm-watcher.git","svn_url":"https://github.com/windbreaker-io/npm-watcher","homepage":null,"size":33,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"windbreaker-io:master","ref":"master","sha":"e5985dd8759681d0f8a0aa76c60f5004f5118648","user":{"login":"windbreaker-io","id":29463585,"avatar_url":"https://avatars3.githubusercontent.com/u/29463585?v=4","gravatar_id":"","url":"https://api.github.com/users/windbreaker-io","html_url":"https://github.com/windbreaker-io","followers_url":"https://api.github.com/users/windbreaker-io/followers","following_url":"https://api.github.com/users/windbreaker-io/following{/other_user}","gists_url":"https://api.github.com/users/windbreaker-io/gists{/gist_id}","starred_url":"https://api.github.com/users/windbreaker-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windbreaker-io/subscriptions","organizations_url":"https://api.github.com/users/windbreaker-io/orgs","repos_url":"https://api.github.com/users/windbreaker-io/repos","events_url":"https://api.github.com/users/windbreaker-io/events{/privacy}","received_events_url":"https://api.github.com/users/windbreaker-io/received_events","type":"Organization","site_admin":false},"repo":{"id":95166245,"name":"npm-watcher","full_name":"windbreaker-io/npm-watcher","owner":{"login":"windbreaker-io","id":29463585,"avatar_url":"https://avatars3.githubusercontent.com/u/29463585?v=4","gravatar_id":"","url":"https://api.github.com/users/windbreaker-io","html_url":"https://github.com/windbreaker-io","followers_url":"https://api.github.com/users/windbreaker-io/followers","following_url":"https://api.github.com/users/windbreaker-io/following{/other_user}","gists_url":"https://api.github.com/users/windbreaker-io/gists{/gist_id}","starred_url":"https://api.github.com/users/windbreaker-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windbreaker-io/subscriptions","organizations_url":"https://api.github.com/users/windbreaker-io/orgs","repos_url":"https://api.github.com/users/windbreaker-io/repos","events_url":"https://api.github.com/users/windbreaker-io/events{/privacy}","received_events_url":"https://api.github.com/users/windbreaker-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/windbreaker-io/npm-watcher","description":"Follow npm registry and pass rabbitmq-compatible changes along to windbreaker","fork":false,"url":"https://api.github.com/repos/windbreaker-io/npm-watcher","forks_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/forks","keys_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/teams","hooks_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/hooks","issue_events_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/events{/number}","events_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/events","assignees_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/assignees{/user}","branches_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/branches{/branch}","tags_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/tags","blobs_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/refs{/sha}","trees_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/statuses/{sha}","languages_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/languages","stargazers_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/stargazers","contributors_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/contributors","subscribers_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/subscribers","subscription_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/subscription","commits_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/commits{/sha}","git_commits_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/git/commits{/sha}","comments_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/comments{/number}","issue_comment_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/comments{/number}","contents_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/contents/{+path}","compare_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/merges","archive_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/downloads","issues_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues{/number}","pulls_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls{/number}","milestones_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/milestones{/number}","notifications_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/labels{/name}","releases_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/releases{/id}","deployments_url":"https://api.github.com/repos/windbreaker-io/npm-watcher/deployments","created_at":"2017-06-22T23:56:25Z","updated_at":"2017-06-24T20:29:41Z","pushed_at":"2017-08-06T20:10:00Z","git_url":"git://github.com/windbreaker-io/npm-watcher.git","ssh_url":"git@github.com:windbreaker-io/npm-watcher.git","clone_url":"https://github.com/windbreaker-io/npm-watcher.git","svn_url":"https://github.com/windbreaker-io/npm-watcher","homepage":null,"size":33,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3"},"html":{"href":"https://github.com/windbreaker-io/npm-watcher/pull/3"},"issue":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/3"},"comments":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/windbreaker-io/npm-watcher/statuses/efe00e5a4fc55c8c768536f2895dd1b911867f5f"}}}}
{"actor":{"display_login":"charlieduong94"}}