{"action":"created","comment":{"url":"https://api.github.com/repos/RackHD/on-core/pulls/comments/52207087","id":52207087,"diff_hunk":"@@ -5,113 +6,254 @@\n \n describe('Connection', function () {\n     var Connection;\n-\n+    var amqp, amqpConnection;\n     helper.before();\n \n     before(function () {\n         Connection = helper.injector.get('Connection');\n-        this.uri  = helper.injector.get('Services.Configuration').get('amqp');\n+        amqp = helper.injector.get('amqp');\n     });\n-\n+    this.uri = 'amqp://localhost';\n     beforeEach(function () {\n-        this.subject = new Connection({\n-            url: this.uri\n-        }, {}, 'test');\n-    });\n+        this.subject = new Connection({url: 'amqp://localhost'}, {}, 'test');\n \n-    afterEach(function () {\n-        if (this.connection && this.connection.connected) {\n-            return this.connection.stop();\n-        }\n     });\n \n     helper.after();\n \n     describe('Connection', function () {\n         describe('start', function () {\n+\n             it('should fulfill on success', function () {\n+                amqp.createConnection = sinon.spy(function () {\n+                    return ({\n+                        'on': function (a, callback) {\n+                            if (a === 'ready') {\n+                                callback(null, {});\n+                            }\n+                        }\n+                    })\n+                })\n                 return this.subject.start();\n             });\n \n-            it('should reject if started twice', function () {\n+            it('should reject on trying to start twice', function () {\n+                amqp.createConnection = sinon.spy(function () {\n+                    return ({\n+                        'on': function (a, callback) {\n+                            callback(null, {});\n+                        }\n+                    })\n+                })\n                 var self = this;\n-\n                 return this.subject.start().then(function () {\n                     return self.subject.start().should.be.rejected;\n                 });\n             });\n \n-            it('should reject on max retry attempts', function() {\n-                this.subject.maxConnectionRetries = 3;\n-                var startPromise = this.subject.start();\n-                this.subject.connection.removeAllListeners('ready');\n-                this.subject.connection.emit('error', new Error('test'));\n-                this.subject.connection.emit('error', new Error('test'));\n-                this.subject.connection.emit('error', new Error('test'));\n-                this.subject.connection.emit('error', new Error('test'));\n-                return expect(startPromise).to.be.rejectedWith(/Exceeded max retries/);\n+            it('should suppress Error Code ECONNRESET', function () {\n+                amqp.createConnection = sinon.spy(function () {\n+                    return ({\n+                        'on': function (a, callback) {\n+                            callback({'code': 'ECONNRESET'}, {});\n+                        }\n+                    })\n+                });\n+                return this.subject.start();\n             });\n \n-            it('should increment retry attempts if initial connection fails', function() {\n-                this.subject.initialConnection = false;\n-                this.subject.start();\n-                this.subject.connection.removeAllListeners('ready');\n-                this.subject.connection.emit('error', new Error('test'));\n-                this.subject.connection.emit('error', new Error('test'));\n-                this.subject.connection.emit('error', new Error('test'));\n-                expect(this.subject.initialConnectionRetries).to.equal(3);\n+            it('should check if initialConnection is true', function () {\n+                this.subject.initialConnection = {};\n+                amqp.createConnection = sinon.spy(function () {\n+                    return ({\n+                        'on': function (a, callback) {\n+                            callback({'message': 'Hit an error'}, {});\n+                        }\n+                    })\n+                })\n+                return this.subject.start();\n             });\n \n-            it('should not increment retry attempts if initial connection succeeded', function() {\n-                this.subject.initialConnection = true;\n-                this.subject.start();\n-                this.subject.connection.removeAllListeners('ready');\n-                this.subject.connection.emit('error', new Error('test'));\n-                this.subject.connection.emit('error', new Error('test'));\n-                expect(this.subject.initialConnectionRetries).to.equal(0);\n+            it('should check if max retries exceeded', function () {\n+                this.subject.initialConnectionRetries = 100;\n+                amqp.createConnection = sinon.spy(function () {\n+                    return ({\n+                        'on': function (a, callback) {\n+                            if (a === 'error') {\n+                                callback({'message': 'error'}, {});\n+                            }\n+                        }\n+                    })\n+                })\n+                return this.subject.start()\n+                    .catch(function (Error) {\n+                        console.log(Error);\n+                    });\n             });\n-        });\n \n-        describe('connected', function () {\n-            it('should be false if not connected', function () {\n-                this.subject.connected.should.equal(false);\n+            describe('connected', function () {\n+                it('should be false if not connected', function () {\n+                    this.subject.connected.should.equal(false);\n+                });\n+\n+                it('should be true if connected', function () {\n+                    var self = this;\n+                    amqp.createConnection = sinon.spy(function () {\n+                        return ({\n+                            'on': function (a, callback) {\n+                                callback(null, {});\n+                            }\n+                        })\n+                    })\n+                    return this.subject.start().then(function () {\n+                        return self.subject.connected.should.equal(true);\n+                    });\n+                });\n             });\n \n-            it('should be true if connected', function () {\n-                var self = this;\n+            describe('exchanges', function () {\n+                it('should be undefined if not connected', function () {\n+                    expect(this.subject.exchanges).equal(undefined);\n+                });\n \n-                return this.subject.start().then(function () {\n-                    return self.subject.connected.should.equal(true);\n+                it('should have exchanges if connected', function () {\n+                    var self = this;\n+\n+                    amqp.createConnection = sinon.spy(function () {\n+                        return ({\n+                            'on': function (a, callback) {\n+                                callback(null, {});\n+                            },\n+                            'exchanges':\n+                                'on.test'\n+                        })\n+                    })\n+                    this.subject.start().then(function () {\n+\n+                        self.subject.exchanges.should.not.be.undefined;\n+                    });\n                 });\n             });\n-        });\n \n-        describe('exchanges', function () {\n-            it('should be undefined if not connected', function () {\n-                expect(this.subject.exchanges).equal(undefined);\n-            });\n+            describe('exchange', function ()  {\n+                it('should not provide an exchange if connection not established ', function () {\n+                    var self = this;\n+                    return this.subject.exchange()\n+                        .catch(function (Error) {\n+                            console.log(Error);\n+                        });\n+                });\n \n-            it('should have exchanges if connected', function () {\n-                var self = this;\n+                it('should provide an exchange if connection established and options is a valid object', function () {\n+                    var self = this;\n+                    amqp.createConnection = sinon.spy(function () {\n+                        return ({\n+                            'on': function (a, callback) {\n+                                callback(null, {});\n+                            },\n+                            'exchange': function (a, b, callback){\n+                                callback('Hello', {})\n+                            },\n+                            'exchanges':\n+                                'on.test'\n+                        })\n+                    })\n+                    this.subject.start().then(function () {\n+                        if (self.subject.connected == true) {\n+                            var name = 'amqp://localhost';\n+                            return self.subject.exchange(name, {url: 'amqp://localhost'}, function(callback) {\n+                                callback('exchange', {});\n+                            });\n+                        }\n+                    });\n+                });\n+\n+                it('should error out if objects is not valid ', function () {\n+                    var self = this;\n+                    amqp.createConnection = sinon.spy(function () {\n+                        return ({\n+                            'on': function (a, callback) {\n+                                callback(null, {});\n+                            },\n+                            'exchange': function (a, b, callback){\n+                                callback('Hello', {})\n+                            },\n+                            'exchanges':\n+                                'on.test'\n+                        })\n+                    })\n+                    this.subject.start().then(function () {\n+                        if (self.subject.connected == true) {","path":"spec/lib/common/connection-spec.js","position":238,"original_position":238,"commit_id":"f93544daee7e5e4633932062f2691599160ad0c9","original_commit_id":"f93544daee7e5e4633932062f2691599160ad0c9","user":{"login":"benbp","id":1020379,"avatar_url":"https://avatars.githubusercontent.com/u/1020379?v=3","gravatar_id":"","url":"https://api.github.com/users/benbp","html_url":"https://github.com/benbp","followers_url":"https://api.github.com/users/benbp/followers","following_url":"https://api.github.com/users/benbp/following{/other_user}","gists_url":"https://api.github.com/users/benbp/gists{/gist_id}","starred_url":"https://api.github.com/users/benbp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benbp/subscriptions","organizations_url":"https://api.github.com/users/benbp/orgs","repos_url":"https://api.github.com/users/benbp/repos","events_url":"https://api.github.com/users/benbp/events{/privacy}","received_events_url":"https://api.github.com/users/benbp/received_events","type":"User","site_admin":false},"body":"Do we want a failure case if `self.subject.connected` does not equal true? Otherwise it's a noop test in this case.","created_at":"2016-02-08T18:43:14Z","updated_at":"2016-02-08T18:43:14Z","html_url":"https://github.com/RackHD/on-core/pull/81#discussion_r52207087","pull_request_url":"https://api.github.com/repos/RackHD/on-core/pulls/81","_links":{"self":{"href":"https://api.github.com/repos/RackHD/on-core/pulls/comments/52207087"},"html":{"href":"https://github.com/RackHD/on-core/pull/81#discussion_r52207087"},"pull_request":{"href":"https://api.github.com/repos/RackHD/on-core/pulls/81"}}},"pull_request":{"url":"https://api.github.com/repos/RackHD/on-core/pulls/81","id":58631832,"html_url":"https://github.com/RackHD/on-core/pull/81","diff_url":"https://github.com/RackHD/on-core/pull/81.diff","patch_url":"https://github.com/RackHD/on-core/pull/81.patch","issue_url":"https://api.github.com/repos/RackHD/on-core/issues/81","number":81,"state":"open","locked":false,"title":"On-core unit test re-factor to remove RabbitMQ dependency","user":{"login":"uppalk1","id":14128586,"avatar_url":"https://avatars.githubusercontent.com/u/14128586?v=3","gravatar_id":"","url":"https://api.github.com/users/uppalk1","html_url":"https://github.com/uppalk1","followers_url":"https://api.github.com/users/uppalk1/followers","following_url":"https://api.github.com/users/uppalk1/following{/other_user}","gists_url":"https://api.github.com/users/uppalk1/gists{/gist_id}","starred_url":"https://api.github.com/users/uppalk1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uppalk1/subscriptions","organizations_url":"https://api.github.com/users/uppalk1/orgs","repos_url":"https://api.github.com/users/uppalk1/repos","events_url":"https://api.github.com/users/uppalk1/events{/privacy}","received_events_url":"https://api.github.com/users/uppalk1/received_events","type":"User","site_admin":false},"body":"\t# refactor connection-spec.js","created_at":"2016-02-08T16:25:36Z","updated_at":"2016-02-08T18:43:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ad5510a88fa07093959299dbfab0195ef5fbf4f1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RackHD/on-core/pulls/81/commits","review_comments_url":"https://api.github.com/repos/RackHD/on-core/pulls/81/comments","review_comment_url":"https://api.github.com/repos/RackHD/on-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RackHD/on-core/issues/81/comments","statuses_url":"https://api.github.com/repos/RackHD/on-core/statuses/f93544daee7e5e4633932062f2691599160ad0c9","head":{"label":"uppalk1:kranti-on-core-refactor","ref":"kranti-on-core-refactor","sha":"f93544daee7e5e4633932062f2691599160ad0c9","user":{"login":"uppalk1","id":14128586,"avatar_url":"https://avatars.githubusercontent.com/u/14128586?v=3","gravatar_id":"","url":"https://api.github.com/users/uppalk1","html_url":"https://github.com/uppalk1","followers_url":"https://api.github.com/users/uppalk1/followers","following_url":"https://api.github.com/users/uppalk1/following{/other_user}","gists_url":"https://api.github.com/users/uppalk1/gists{/gist_id}","starred_url":"https://api.github.com/users/uppalk1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uppalk1/subscriptions","organizations_url":"https://api.github.com/users/uppalk1/orgs","repos_url":"https://api.github.com/users/uppalk1/repos","events_url":"https://api.github.com/users/uppalk1/events{/privacy}","received_events_url":"https://api.github.com/users/uppalk1/received_events","type":"User","site_admin":false},"repo":{"id":50112963,"name":"on-core","full_name":"uppalk1/on-core","owner":{"login":"uppalk1","id":14128586,"avatar_url":"https://avatars.githubusercontent.com/u/14128586?v=3","gravatar_id":"","url":"https://api.github.com/users/uppalk1","html_url":"https://github.com/uppalk1","followers_url":"https://api.github.com/users/uppalk1/followers","following_url":"https://api.github.com/users/uppalk1/following{/other_user}","gists_url":"https://api.github.com/users/uppalk1/gists{/gist_id}","starred_url":"https://api.github.com/users/uppalk1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uppalk1/subscriptions","organizations_url":"https://api.github.com/users/uppalk1/orgs","repos_url":"https://api.github.com/users/uppalk1/repos","events_url":"https://api.github.com/users/uppalk1/events{/privacy}","received_events_url":"https://api.github.com/users/uppalk1/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/uppalk1/on-core","description":"","fork":true,"url":"https://api.github.com/repos/uppalk1/on-core","forks_url":"https://api.github.com/repos/uppalk1/on-core/forks","keys_url":"https://api.github.com/repos/uppalk1/on-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uppalk1/on-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uppalk1/on-core/teams","hooks_url":"https://api.github.com/repos/uppalk1/on-core/hooks","issue_events_url":"https://api.github.com/repos/uppalk1/on-core/issues/events{/number}","events_url":"https://api.github.com/repos/uppalk1/on-core/events","assignees_url":"https://api.github.com/repos/uppalk1/on-core/assignees{/user}","branches_url":"https://api.github.com/repos/uppalk1/on-core/branches{/branch}","tags_url":"https://api.github.com/repos/uppalk1/on-core/tags","blobs_url":"https://api.github.com/repos/uppalk1/on-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uppalk1/on-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uppalk1/on-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/uppalk1/on-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uppalk1/on-core/statuses/{sha}","languages_url":"https://api.github.com/repos/uppalk1/on-core/languages","stargazers_url":"https://api.github.com/repos/uppalk1/on-core/stargazers","contributors_url":"https://api.github.com/repos/uppalk1/on-core/contributors","subscribers_url":"https://api.github.com/repos/uppalk1/on-core/subscribers","subscription_url":"https://api.github.com/repos/uppalk1/on-core/subscription","commits_url":"https://api.github.com/repos/uppalk1/on-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/uppalk1/on-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/uppalk1/on-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/uppalk1/on-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/uppalk1/on-core/contents/{+path}","compare_url":"https://api.github.com/repos/uppalk1/on-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uppalk1/on-core/merges","archive_url":"https://api.github.com/repos/uppalk1/on-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uppalk1/on-core/downloads","issues_url":"https://api.github.com/repos/uppalk1/on-core/issues{/number}","pulls_url":"https://api.github.com/repos/uppalk1/on-core/pulls{/number}","milestones_url":"https://api.github.com/repos/uppalk1/on-core/milestones{/number}","notifications_url":"https://api.github.com/repos/uppalk1/on-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uppalk1/on-core/labels{/name}","releases_url":"https://api.github.com/repos/uppalk1/on-core/releases{/id}","deployments_url":"https://api.github.com/repos/uppalk1/on-core/deployments","created_at":"2016-01-21T14:29:08Z","updated_at":"2016-01-21T14:29:08Z","pushed_at":"2016-02-08T16:03:57Z","git_url":"git://github.com/uppalk1/on-core.git","ssh_url":"git@github.com:uppalk1/on-core.git","clone_url":"https://github.com/uppalk1/on-core.git","svn_url":"https://github.com/uppalk1/on-core","homepage":null,"size":765,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"RackHD:master","ref":"master","sha":"e0efc1a8671facb404e7dd981eba984854d56b54","user":{"login":"RackHD","id":13982662,"avatar_url":"https://avatars.githubusercontent.com/u/13982662?v=3","gravatar_id":"","url":"https://api.github.com/users/RackHD","html_url":"https://github.com/RackHD","followers_url":"https://api.github.com/users/RackHD/followers","following_url":"https://api.github.com/users/RackHD/following{/other_user}","gists_url":"https://api.github.com/users/RackHD/gists{/gist_id}","starred_url":"https://api.github.com/users/RackHD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RackHD/subscriptions","organizations_url":"https://api.github.com/users/RackHD/orgs","repos_url":"https://api.github.com/users/RackHD/repos","events_url":"https://api.github.com/users/RackHD/events{/privacy}","received_events_url":"https://api.github.com/users/RackHD/received_events","type":"Organization","site_admin":false},"repo":{"id":41690044,"name":"on-core","full_name":"RackHD/on-core","owner":{"login":"RackHD","id":13982662,"avatar_url":"https://avatars.githubusercontent.com/u/13982662?v=3","gravatar_id":"","url":"https://api.github.com/users/RackHD","html_url":"https://github.com/RackHD","followers_url":"https://api.github.com/users/RackHD/followers","following_url":"https://api.github.com/users/RackHD/following{/other_user}","gists_url":"https://api.github.com/users/RackHD/gists{/gist_id}","starred_url":"https://api.github.com/users/RackHD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RackHD/subscriptions","organizations_url":"https://api.github.com/users/RackHD/orgs","repos_url":"https://api.github.com/users/RackHD/repos","events_url":"https://api.github.com/users/RackHD/events{/privacy}","received_events_url":"https://api.github.com/users/RackHD/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RackHD/on-core","description":"","fork":false,"url":"https://api.github.com/repos/RackHD/on-core","forks_url":"https://api.github.com/repos/RackHD/on-core/forks","keys_url":"https://api.github.com/repos/RackHD/on-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RackHD/on-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RackHD/on-core/teams","hooks_url":"https://api.github.com/repos/RackHD/on-core/hooks","issue_events_url":"https://api.github.com/repos/RackHD/on-core/issues/events{/number}","events_url":"https://api.github.com/repos/RackHD/on-core/events","assignees_url":"https://api.github.com/repos/RackHD/on-core/assignees{/user}","branches_url":"https://api.github.com/repos/RackHD/on-core/branches{/branch}","tags_url":"https://api.github.com/repos/RackHD/on-core/tags","blobs_url":"https://api.github.com/repos/RackHD/on-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RackHD/on-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RackHD/on-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/RackHD/on-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RackHD/on-core/statuses/{sha}","languages_url":"https://api.github.com/repos/RackHD/on-core/languages","stargazers_url":"https://api.github.com/repos/RackHD/on-core/stargazers","contributors_url":"https://api.github.com/repos/RackHD/on-core/contributors","subscribers_url":"https://api.github.com/repos/RackHD/on-core/subscribers","subscription_url":"https://api.github.com/repos/RackHD/on-core/subscription","commits_url":"https://api.github.com/repos/RackHD/on-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/RackHD/on-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/RackHD/on-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/RackHD/on-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/RackHD/on-core/contents/{+path}","compare_url":"https://api.github.com/repos/RackHD/on-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RackHD/on-core/merges","archive_url":"https://api.github.com/repos/RackHD/on-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RackHD/on-core/downloads","issues_url":"https://api.github.com/repos/RackHD/on-core/issues{/number}","pulls_url":"https://api.github.com/repos/RackHD/on-core/pulls{/number}","milestones_url":"https://api.github.com/repos/RackHD/on-core/milestones{/number}","notifications_url":"https://api.github.com/repos/RackHD/on-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RackHD/on-core/labels{/name}","releases_url":"https://api.github.com/repos/RackHD/on-core/releases{/id}","deployments_url":"https://api.github.com/repos/RackHD/on-core/deployments","created_at":"2015-08-31T17:28:32Z","updated_at":"2016-01-31T09:01:09Z","pushed_at":"2016-02-08T16:25:36Z","git_url":"git://github.com/RackHD/on-core.git","ssh_url":"git@github.com:RackHD/on-core.git","clone_url":"https://github.com/RackHD/on-core.git","svn_url":"https://github.com/RackHD/on-core","homepage":null,"size":857,"stargazers_count":9,"watchers_count":9,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":6,"forks":24,"open_issues":6,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RackHD/on-core/pulls/81"},"html":{"href":"https://github.com/RackHD/on-core/pull/81"},"issue":{"href":"https://api.github.com/repos/RackHD/on-core/issues/81"},"comments":{"href":"https://api.github.com/repos/RackHD/on-core/issues/81/comments"},"review_comments":{"href":"https://api.github.com/repos/RackHD/on-core/pulls/81/comments"},"review_comment":{"href":"https://api.github.com/repos/RackHD/on-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RackHD/on-core/pulls/81/commits"},"statuses":{"href":"https://api.github.com/repos/RackHD/on-core/statuses/f93544daee7e5e4633932062f2691599160ad0c9"}}}}