DEV: Fix failing click-track tests.

DEV: Fix failing click-track tests.

diff --git a/app/assets/javascripts/discourse/lib/click-track.js.es6 b/app/assets/javascripts/discourse/lib/click-track.js.es6
index dae52b7..d744929 100644
--- a/app/assets/javascripts/discourse/lib/click-track.js.es6
+++ b/app/assets/javascripts/discourse/lib/click-track.js.es6
@@ -93,7 +93,7 @@ export default {
 
     let trackPromise = Ember.RSVP.resolve();
     if (tracking) {
-      if (navigator.sendBeacon) {
+      if (!Ember.testing && navigator.sendBeacon) {
         const data = new FormData();
         data.append("url", href);
         data.append("post_id", postId);
diff --git a/test/javascripts/acceptance/click-track-test.js.es6 b/test/javascripts/acceptance/click-track-test.js.es6
index ddbb435..6abc41d 100644
--- a/test/javascripts/acceptance/click-track-test.js.es6
+++ b/test/javascripts/acceptance/click-track-test.js.es6
@@ -4,7 +4,7 @@ acceptance("Click Track", {});
 
 QUnit.test("Do not track mentions", async assert => {
   /* global server */
-  server.get("/clicks/track", () => assert.ok(false));
+  server.post("/clicks/track", () => assert.ok(false));
 
   await visit("/t/internationalization-localization/280");
   assert.ok(invisible("#user-card"), "card should not appear");
diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6
index 2054a13..9837a53 100644
--- a/test/javascripts/helpers/create-pretender.js.es6
+++ b/test/javascripts/helpers/create-pretender.js.es6
@@ -138,7 +138,7 @@ export default function() {
       return response({ topic_list: { topics: [] } });
     });
 
-    this.get("/clicks/track", success);
+    this.post("/clicks/track", success);
 
     this.get("/search", request => {
       if (request.queryParams.q === "posts") {
diff --git a/test/javascripts/lib/click-track-edit-history-test.js.es6 b/test/javascripts/lib/click-track-edit-history-test.js.es6
index 191df96..0081151 100644
--- a/test/javascripts/lib/click-track-edit-history-test.js.es6
+++ b/test/javascripts/lib/click-track-edit-history-test.js.es6
@@ -62,11 +62,10 @@ QUnit.test("tracks internal URLs", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
-    assert.ok(
-      request.url.indexOf(
-        "url=http%3A%2F%2Fdiscuss.domain.com&post_id=42&topic_id=1337"
-      ) !== -1
+  server.post("/clicks/track", request => {
+    assert.equal(
+      request.requestBody,
+      "url=http%3A%2F%2Fdiscuss.domain.com&post_id=42&topic_id=1337"
     );
     done();
   });
@@ -79,11 +78,10 @@ QUnit.test("tracks external URLs", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
-    assert.ok(
-      request.url.indexOf(
-        "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
-      ) !== -1
+  server.post("/clicks/track", request => {
+    assert.equal(
+      request.requestBody,
+      "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
     );
     done();
   });
@@ -99,11 +97,10 @@ QUnit.test(
 
     const done = assert.async();
     /* global server */
-    server.get("/clicks/track", request => {
-      assert.ok(
-        request.url.indexOf(
-          "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
-        ) !== -1
+    server.post("/clicks/track", request => {
+      assert.equal(
+        request.requestBody,
+        "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
       );
       done();
     });
diff --git a/test/javascripts/lib/click-track-profile-page-test.js.es6 b/test/javascripts/lib/click-track-profile-page-test.js.es6
index 0face6b..3496626 100644
--- a/test/javascripts/lib/click-track-profile-page-test.js.es6
+++ b/test/javascripts/lib/click-track-profile-page-test.js.es6
@@ -56,10 +56,8 @@ QUnit.test("tracks internal URLs", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
-    assert.ok(
-      request.url.indexOf("url=http%3A%2F%2Fdiscuss.domain.com") !== -1
-    );
+  server.post("/clicks/track", request => {
+    assert.equal(request.requestBody, "url=http%3A%2F%2Fdiscuss.domain.com");
     done();
   });
 
@@ -71,11 +69,10 @@ QUnit.test("tracks external URLs", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
-    assert.ok(
-      request.url.indexOf(
-        "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
-      ) !== -1
+  server.post("/clicks/track", request => {
+    assert.equal(
+      request.requestBody,
+      "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
     );
     done();
   });
@@ -88,11 +85,10 @@ QUnit.test("tracks external URLs in other posts", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
-    assert.ok(
-      request.url.indexOf(
-        "url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"
-      ) !== -1
+  server.post("/clicks/track", request => {
+    assert.equal(
+      request.requestBody,
+      "url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"
     );
     done();
   });
diff --git a/test/javascripts/lib/click-track-test.js.es6 b/test/javascripts/lib/click-track-test.js.es6
index 8e4d1f8..d69b233 100644
--- a/test/javascripts/lib/click-track-test.js.es6
+++ b/test/javascripts/lib/click-track-test.js.es6
@@ -54,11 +54,10 @@ QUnit.test("tracks internal URLs", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
+  server.post("/clicks/track", request => {
     assert.ok(
-      request.url.indexOf(
-        "url=http%3A%2F%2Fdiscuss.domain.com&post_id=42&topic_id=1337"
-      ) !== -1
+      request.requestBody,
+      "url=http%3A%2F%2Fdiscuss.domain.com&post_id=42&topic_id=1337"
     );
     done();
   });
@@ -75,7 +74,7 @@ QUnit.test("does not track attachments", async assert => {
   sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");
 
   /* global server */
-  server.get("/clicks/track", () => assert.ok(false));
+  server.post("/clicks/track", () => assert.ok(false));
 
   assert.ok(track(generateClickEventOn(".attachment")));
 });
@@ -85,11 +84,10 @@ QUnit.test("tracks external URLs", async assert => {
 
   const done = assert.async();
   /* global server */
-  server.get("/clicks/track", request => {
+  server.post("/clicks/track", request => {
     assert.ok(
-      request.url.indexOf(
-        "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
-      ) !== -1
+      request.requestBody,
+      "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
     );
     done();
   });
@@ -105,11 +103,10 @@ QUnit.test(
 
     const done = assert.async();
     /* global server */
-    server.get("/clicks/track", request => {
+    server.post("/clicks/track", request => {
       assert.ok(
-        request.url.indexOf(
-          "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
-        ) !== -1
+        request.requestBody,
+        "url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"
       );
       done();
     });

GitHub sha: 71fb8a41

2 Likes