{"action":"created","comment":{"url":"https://api.github.com/repos/jembi/openhim-core-js/pulls/comments/24327262","id":24327262,"diff_hunk":"@@ -0,0 +1,91 @@\n+fs = require \"fs\"\n+should = require \"should\"\n+sinon = require \"sinon\"\n+http = require \"http\"\n+stats = require \"../../lib/middleware/stats\"\n+testUtils = require \"../testUtils\"\n+FakeServer = require \"../fakeTcpServer\"\n+timer = new Date()\n+config = require '../../lib/config/config'\n+application = config.get 'application'\n+os = require \"os\"\n+domain = os.hostname() + '.' + application.name\n+\n+\n+\n+describe \"Stats Middleware \", ->\n+  s = {}\n+\n+  before (done) ->\n+    s = new FakeServer()\n+    s.start done\n+\n+  after ->\n+    s.stop()\n+\n+\n+  channel =\n+    _id: \"ckjhfjwedsnfdsf\"\n+    name: \"Mock endpoint\"\n+    urlPattern: \".+\"\n+    routes: [\n+      secured: true\n+      host: 'localhost'\n+      port: 9877\n+      primary: true\n+      cert: fs.readFileSync 'test/resources/server-tls/cert.pem'\n+    ]\n+\n+  requestTimestamp = (new Date()).toString()\n+  ctx = new Object()\n+  ctx.authorisedChannel = channel\n+  ctx.request = new Object()\n+  ctx.response = new Object()\n+  ctx.response.set = ->\n+  ctx.path = ctx.request.url = \"/test\"\n+  ctx.request.method = \"GET\"\n+  ctx.requestTimestamp = requestTimestamp\n+  ctx.transactionStatus = \"Successful\"\n+\n+#  TODO add orchestrations and non primary routes to the ctx object\n+  ctx.mediatorResponse = orchestrations: [\n+    name: \"Lab API\"\n+    request:\n+      path: \"api/patient/lab\"\n+      headers:\n+        \"Content-Type\": \"text/plain\"\n+      body: \"<route request>\"\n+      method: \"POST\"\n+      timestamp: 1412257881904\n+    response:\n+      status: \"200\"\n+      headers: {}\n+      body: \"<route response>\"\n+      timestamp: 1412257881909\n+  ]\n+\n+\n+\n+  it \"should increment the transaction counter\", (done) ->\n+    this.timeout = 400000\n+    stats.incrementTransactionCount ctx, () ->\n+      s.expectMessage domain + '.channels:1|c', ->\n+        s.expectMessage domain + '.channels.Successful:1|c', ->\n+          s.expectMessage domain + '.channels.ckjhfjwedsnfdsf:1|c', ->\n+            s.expectMessage domain + '.channels.ckjhfjwedsnfdsf.orchestrations.Lab API:1|c', ->\n+              s.expectMessage domain + '.channels.ckjhfjwedsnfdsf.orchestrations.Lab API.statusCodes.200:1|c', ->\n+                s.expectMessage domain + '.channels.ckjhfjwedsnfdsf.statuses.Successful.orchestrations.Lab API:1|c', ->\n+                  s.expectMessage domain + '.channels.ckjhfjwedsnfdsf.statuses.Successful.orchestrations.Lab API.statusCodes.200:1|c', done\n+\n+#  it \"Should measure transaction duration\", (done) ->\n+#    this.timeout = 900000\n+#    stats.timer = new Date()\n+#    stats.measureTransactionDuration ctx, () ->\n+#      s._packetsReceived.forEach (item, index) ->\n+#        console.log s._packetsReceived[index].toString()\n+#      s.expectMessage '', done","path":"test/unit/statsMiddlewareTest.coffee","position":86,"original_position":86,"commit_id":"c0e1580c3edd0fafa845437fad35d6d84ba8b5e9","original_commit_id":"c0e1580c3edd0fafa845437fad35d6d84ba8b5e9","user":{"login":"rcrichton","id":266576,"avatar_url":"https://avatars.githubusercontent.com/u/266576?v=3","gravatar_id":"","url":"https://api.github.com/users/rcrichton","html_url":"https://github.com/rcrichton","followers_url":"https://api.github.com/users/rcrichton/followers","following_url":"https://api.github.com/users/rcrichton/following{/other_user}","gists_url":"https://api.github.com/users/rcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/rcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rcrichton/subscriptions","organizations_url":"https://api.github.com/users/rcrichton/orgs","repos_url":"https://api.github.com/users/rcrichton/repos","events_url":"https://api.github.com/users/rcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/rcrichton/received_events","type":"User","site_admin":false},"body":"Why is this code commented out? I think its a good idea to ensure the duration are send correctly.","created_at":"2015-02-09T13:27:50Z","updated_at":"2015-02-09T13:27:50Z","html_url":"https://github.com/jembi/openhim-core-js/pull/323#discussion_r24327262","pull_request_url":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323","_links":{"self":{"href":"https://api.github.com/repos/jembi/openhim-core-js/pulls/comments/24327262"},"html":{"href":"https://github.com/jembi/openhim-core-js/pull/323#discussion_r24327262"},"pull_request":{"href":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323"}}},"pull_request":{"url":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323","id":27196217,"html_url":"https://github.com/jembi/openhim-core-js/pull/323","diff_url":"https://github.com/jembi/openhim-core-js/pull/323.diff","patch_url":"https://github.com/jembi/openhim-core-js/pull/323.patch","issue_url":"https://api.github.com/repos/jembi/openhim-core-js/issues/323","number":323,"state":"open","locked":false,"title":"Statsd model","user":{"login":"debonair","id":618654,"avatar_url":"https://avatars.githubusercontent.com/u/618654?v=3","gravatar_id":"","url":"https://api.github.com/users/debonair","html_url":"https://github.com/debonair","followers_url":"https://api.github.com/users/debonair/followers","following_url":"https://api.github.com/users/debonair/following{/other_user}","gists_url":"https://api.github.com/users/debonair/gists{/gist_id}","starred_url":"https://api.github.com/users/debonair/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/debonair/subscriptions","organizations_url":"https://api.github.com/users/debonair/orgs","repos_url":"https://api.github.com/users/debonair/repos","events_url":"https://api.github.com/users/debonair/events{/privacy}","received_events_url":"https://api.github.com/users/debonair/received_events","type":"User","site_admin":false},"body":"@rcrichton please review","created_at":"2015-01-12T14:12:01Z","updated_at":"2015-02-09T13:27:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3039939ecd4750e401a7af1791be52d8345c4712","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323/commits","review_comments_url":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323/comments","review_comment_url":"https://api.github.com/repos/jembi/openhim-core-js/pulls/comments/{number}","comments_url":"https://api.github.com/repos/jembi/openhim-core-js/issues/323/comments","statuses_url":"https://api.github.com/repos/jembi/openhim-core-js/statuses/c0e1580c3edd0fafa845437fad35d6d84ba8b5e9","head":{"label":"jembi:statsd-model","ref":"statsd-model","sha":"c0e1580c3edd0fafa845437fad35d6d84ba8b5e9","user":{"login":"jembi","id":1931511,"avatar_url":"https://avatars.githubusercontent.com/u/1931511?v=3","gravatar_id":"","url":"https://api.github.com/users/jembi","html_url":"https://github.com/jembi","followers_url":"https://api.github.com/users/jembi/followers","following_url":"https://api.github.com/users/jembi/following{/other_user}","gists_url":"https://api.github.com/users/jembi/gists{/gist_id}","starred_url":"https://api.github.com/users/jembi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jembi/subscriptions","organizations_url":"https://api.github.com/users/jembi/orgs","repos_url":"https://api.github.com/users/jembi/repos","events_url":"https://api.github.com/users/jembi/events{/privacy}","received_events_url":"https://api.github.com/users/jembi/received_events","type":"Organization","site_admin":false},"repo":{"id":16686826,"name":"openhim-core-js","full_name":"jembi/openhim-core-js","owner":{"login":"jembi","id":1931511,"avatar_url":"https://avatars.githubusercontent.com/u/1931511?v=3","gravatar_id":"","url":"https://api.github.com/users/jembi","html_url":"https://github.com/jembi","followers_url":"https://api.github.com/users/jembi/followers","following_url":"https://api.github.com/users/jembi/following{/other_user}","gists_url":"https://api.github.com/users/jembi/gists{/gist_id}","starred_url":"https://api.github.com/users/jembi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jembi/subscriptions","organizations_url":"https://api.github.com/users/jembi/orgs","repos_url":"https://api.github.com/users/jembi/repos","events_url":"https://api.github.com/users/jembi/events{/privacy}","received_events_url":"https://api.github.com/users/jembi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jembi/openhim-core-js","description":"The open health information mediator core component","fork":false,"url":"https://api.github.com/repos/jembi/openhim-core-js","forks_url":"https://api.github.com/repos/jembi/openhim-core-js/forks","keys_url":"https://api.github.com/repos/jembi/openhim-core-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jembi/openhim-core-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jembi/openhim-core-js/teams","hooks_url":"https://api.github.com/repos/jembi/openhim-core-js/hooks","issue_events_url":"https://api.github.com/repos/jembi/openhim-core-js/issues/events{/number}","events_url":"https://api.github.com/repos/jembi/openhim-core-js/events","assignees_url":"https://api.github.com/repos/jembi/openhim-core-js/assignees{/user}","branches_url":"https://api.github.com/repos/jembi/openhim-core-js/branches{/branch}","tags_url":"https://api.github.com/repos/jembi/openhim-core-js/tags","blobs_url":"https://api.github.com/repos/jembi/openhim-core-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jembi/openhim-core-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jembi/openhim-core-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/jembi/openhim-core-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jembi/openhim-core-js/statuses/{sha}","languages_url":"https://api.github.com/repos/jembi/openhim-core-js/languages","stargazers_url":"https://api.github.com/repos/jembi/openhim-core-js/stargazers","contributors_url":"https://api.github.com/repos/jembi/openhim-core-js/contributors","subscribers_url":"https://api.github.com/repos/jembi/openhim-core-js/subscribers","subscription_url":"https://api.github.com/repos/jembi/openhim-core-js/subscription","commits_url":"https://api.github.com/repos/jembi/openhim-core-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/jembi/openhim-core-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/jembi/openhim-core-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/jembi/openhim-core-js/issues/comments/{number}","contents_url":"https://api.github.com/repos/jembi/openhim-core-js/contents/{+path}","compare_url":"https://api.github.com/repos/jembi/openhim-core-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jembi/openhim-core-js/merges","archive_url":"https://api.github.com/repos/jembi/openhim-core-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jembi/openhim-core-js/downloads","issues_url":"https://api.github.com/repos/jembi/openhim-core-js/issues{/number}","pulls_url":"https://api.github.com/repos/jembi/openhim-core-js/pulls{/number}","milestones_url":"https://api.github.com/repos/jembi/openhim-core-js/milestones{/number}","notifications_url":"https://api.github.com/repos/jembi/openhim-core-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jembi/openhim-core-js/labels{/name}","releases_url":"https://api.github.com/repos/jembi/openhim-core-js/releases{/id}","created_at":"2014-02-10T06:41:52Z","updated_at":"2015-02-09T09:01:29Z","pushed_at":"2015-02-09T09:01:29Z","git_url":"git://github.com/jembi/openhim-core-js.git","ssh_url":"git@github.com:jembi/openhim-core-js.git","clone_url":"https://github.com/jembi/openhim-core-js.git","svn_url":"https://github.com/jembi/openhim-core-js","homepage":"","size":3841,"stargazers_count":1,"watchers_count":1,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":43,"forks":3,"open_issues":43,"watchers":1,"default_branch":"master"}},"base":{"label":"jembi:master","ref":"master","sha":"1f7efa6da605b8306c2210de6dd004ce742e30e5","user":{"login":"jembi","id":1931511,"avatar_url":"https://avatars.githubusercontent.com/u/1931511?v=3","gravatar_id":"","url":"https://api.github.com/users/jembi","html_url":"https://github.com/jembi","followers_url":"https://api.github.com/users/jembi/followers","following_url":"https://api.github.com/users/jembi/following{/other_user}","gists_url":"https://api.github.com/users/jembi/gists{/gist_id}","starred_url":"https://api.github.com/users/jembi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jembi/subscriptions","organizations_url":"https://api.github.com/users/jembi/orgs","repos_url":"https://api.github.com/users/jembi/repos","events_url":"https://api.github.com/users/jembi/events{/privacy}","received_events_url":"https://api.github.com/users/jembi/received_events","type":"Organization","site_admin":false},"repo":{"id":16686826,"name":"openhim-core-js","full_name":"jembi/openhim-core-js","owner":{"login":"jembi","id":1931511,"avatar_url":"https://avatars.githubusercontent.com/u/1931511?v=3","gravatar_id":"","url":"https://api.github.com/users/jembi","html_url":"https://github.com/jembi","followers_url":"https://api.github.com/users/jembi/followers","following_url":"https://api.github.com/users/jembi/following{/other_user}","gists_url":"https://api.github.com/users/jembi/gists{/gist_id}","starred_url":"https://api.github.com/users/jembi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jembi/subscriptions","organizations_url":"https://api.github.com/users/jembi/orgs","repos_url":"https://api.github.com/users/jembi/repos","events_url":"https://api.github.com/users/jembi/events{/privacy}","received_events_url":"https://api.github.com/users/jembi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jembi/openhim-core-js","description":"The open health information mediator core component","fork":false,"url":"https://api.github.com/repos/jembi/openhim-core-js","forks_url":"https://api.github.com/repos/jembi/openhim-core-js/forks","keys_url":"https://api.github.com/repos/jembi/openhim-core-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jembi/openhim-core-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jembi/openhim-core-js/teams","hooks_url":"https://api.github.com/repos/jembi/openhim-core-js/hooks","issue_events_url":"https://api.github.com/repos/jembi/openhim-core-js/issues/events{/number}","events_url":"https://api.github.com/repos/jembi/openhim-core-js/events","assignees_url":"https://api.github.com/repos/jembi/openhim-core-js/assignees{/user}","branches_url":"https://api.github.com/repos/jembi/openhim-core-js/branches{/branch}","tags_url":"https://api.github.com/repos/jembi/openhim-core-js/tags","blobs_url":"https://api.github.com/repos/jembi/openhim-core-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jembi/openhim-core-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jembi/openhim-core-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/jembi/openhim-core-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jembi/openhim-core-js/statuses/{sha}","languages_url":"https://api.github.com/repos/jembi/openhim-core-js/languages","stargazers_url":"https://api.github.com/repos/jembi/openhim-core-js/stargazers","contributors_url":"https://api.github.com/repos/jembi/openhim-core-js/contributors","subscribers_url":"https://api.github.com/repos/jembi/openhim-core-js/subscribers","subscription_url":"https://api.github.com/repos/jembi/openhim-core-js/subscription","commits_url":"https://api.github.com/repos/jembi/openhim-core-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/jembi/openhim-core-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/jembi/openhim-core-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/jembi/openhim-core-js/issues/comments/{number}","contents_url":"https://api.github.com/repos/jembi/openhim-core-js/contents/{+path}","compare_url":"https://api.github.com/repos/jembi/openhim-core-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jembi/openhim-core-js/merges","archive_url":"https://api.github.com/repos/jembi/openhim-core-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jembi/openhim-core-js/downloads","issues_url":"https://api.github.com/repos/jembi/openhim-core-js/issues{/number}","pulls_url":"https://api.github.com/repos/jembi/openhim-core-js/pulls{/number}","milestones_url":"https://api.github.com/repos/jembi/openhim-core-js/milestones{/number}","notifications_url":"https://api.github.com/repos/jembi/openhim-core-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jembi/openhim-core-js/labels{/name}","releases_url":"https://api.github.com/repos/jembi/openhim-core-js/releases{/id}","created_at":"2014-02-10T06:41:52Z","updated_at":"2015-02-09T09:01:29Z","pushed_at":"2015-02-09T09:01:29Z","git_url":"git://github.com/jembi/openhim-core-js.git","ssh_url":"git@github.com:jembi/openhim-core-js.git","clone_url":"https://github.com/jembi/openhim-core-js.git","svn_url":"https://github.com/jembi/openhim-core-js","homepage":"","size":3841,"stargazers_count":1,"watchers_count":1,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":43,"forks":3,"open_issues":43,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323"},"html":{"href":"https://github.com/jembi/openhim-core-js/pull/323"},"issue":{"href":"https://api.github.com/repos/jembi/openhim-core-js/issues/323"},"comments":{"href":"https://api.github.com/repos/jembi/openhim-core-js/issues/323/comments"},"review_comments":{"href":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323/comments"},"review_comment":{"href":"https://api.github.com/repos/jembi/openhim-core-js/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/jembi/openhim-core-js/pulls/323/commits"},"statuses":{"href":"https://api.github.com/repos/jembi/openhim-core-js/statuses/c0e1580c3edd0fafa845437fad35d6d84ba8b5e9"}}}}