DEV: Add more tests.

DEV: Add more tests.
From 3b7aa54bf3826a03b3a45fa364dc10d46c5420d8 Mon Sep 17 00:00:00 2001
From: Dan Ungureanu <dan@ungureanu.me>
Date: Fri, 7 Dec 2018 18:32:47 +0200
Subject: [PATCH] DEV: Add more tests.


diff --git a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6 b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
index ddcb7b2..adfcd0f 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
+++ b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
@@ -103,7 +103,7 @@ export default {
             passphraseKey => exportPrivateKey(privateKey, passphraseKey)
           );
 
-          return Promise.all([publicStr, privateStr, salt]);
+          return Ember.RSVP.Promise.all([publicStr, privateStr, salt]);
         })
 
         // 3. Save keys to server.
@@ -116,12 +116,17 @@ export default {
             data: { public_key: publicStr, private_key: privateStr, salt }
           });
 
-          return Promise.all([publicStr, privateStr, salt, saveKeys]);
+          return Ember.RSVP.Promise.all([
+            publicStr,
+            privateStr,
+            salt,
+            saveKeys
+          ]);
         })
 
         // 4. Re-import keys but this time as `unextractable`.
         .then(([publicStr, privateStr, salt]) =>
-          Promise.all([
+          Ember.RSVP.Promise.all([
             importPublicKey(publicStr),
             generatePassphraseKey(this.get("passphrase"), salt).then(
               passphraseKey => importPrivateKey(privateStr, passphraseKey)
@@ -135,18 +140,16 @@ export default {
         )
 
         // 6. Reset component status.
-        .then(() =>
-          Ember.run(() => {
-            this.appEvents.trigger("encrypt:status-changed");
-
-            this.send("hidePassphraseInput");
-            this.setProperties({
-              inProgress: false,
-              isEncryptEnabled: true,
-              isEncryptActive: true
-            });
-          })
-        )
+        .then(() => {
+          this.appEvents.trigger("encrypt:status-changed");
+
+          this.send("hidePassphraseInput");
+          this.setProperties({
+            inProgress: false,
+            isEncryptEnabled: true,
+            isEncryptActive: true
+          });
+        })
 
         .catch(popupAjaxError);
     },
@@ -166,7 +169,7 @@ export default {
         passphraseKey => importPrivateKey(privateStr, passphraseKey)
       );
 
-      Promise.all([importPub, importPrv])
+      Ember.RSVP.Promise.all([importPub, importPrv])
 
         // 2. Save key pair in local IndexedDb.
         .then(([publicKey, privateKey]) =>
@@ -174,18 +177,16 @@ export default {
         )
 
         // 3. Reset component status.
-        .then(() =>
-          Ember.run(() => {
-            this.appEvents.trigger("encrypt:status-changed");
-
-            this.send("hidePassphraseInput");
-            this.setProperties({
-              inProgress: false,
-              isEncryptEnabled: true,
-              isEncryptActive: true
-            });
-          })
-        )
+        .then(() => {
+          this.appEvents.trigger("encrypt:status-changed");
+
+          this.send("hidePassphraseInput");
+          this.setProperties({
+            inProgress: false,
+            isEncryptEnabled: true,
+            isEncryptActive: true
+          });
+        })
 
         .catch(() => {
           this.set("inProgress", false);
@@ -211,7 +212,7 @@ export default {
       );
       const p1 = generatePassphraseKey(passphrase, salt);
 
-      Promise.all([p0, p1])
+      Ember.RSVP.Promise.all([p0, p1])
 
         // 2. Encrypt private key with new passphrase key.
         .then(([privateKey, passphraseKey]) =>
diff --git a/assets/javascripts/discourse/controllers/activate-encrypt.js.es6 b/assets/javascripts/discourse/controllers/activate-encrypt.js.es6
index 6a3d24a..b41ca25 100644
--- a/assets/javascripts/discourse/controllers/activate-encrypt.js.es6
+++ b/assets/javascripts/discourse/controllers/activate-encrypt.js.es6
@@ -45,7 +45,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
         passphraseKey => importPrivateKey(privateStr, passphraseKey)
       );
 
-      Promise.all([importPub, importPrv])
+      Ember.RSVP.Promise.all([importPub, importPrv])
 
         // 2. Save key pair in local IndexedDb.
         .then(([publicKey, privateKey]) =>
diff --git a/assets/javascripts/discourse/initializers/hook-composer.js.es6 b/assets/javascripts/discourse/initializers/hook-composer.js.es6
index bc85584..b3d2d09 100644
--- a/assets/javascripts/discourse/initializers/hook-composer.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-composer.js.es6
@@ -104,7 +104,7 @@ export default {
                 });
               });
 
-              return Promise.all([p0, p1]);
+              return Ember.RSVP.Promise.all([p0, p1]);
             })
             .then(() => _super.call(this, ...arguments))
             .finally(() => this.setProperties({ title, reply }));
@@ -131,7 +131,7 @@ export default {
               for (let i = 0; i < usernames.length; ++i) {
                 const username = usernames[i];
                 if (!userKeys[username]) {
-                  promises.push(Promise.reject(username));
+                  promises.push(Ember.RSVP.Promise.reject(username));
                 } else {
                   promises.push(
                     importPublicKey(userKeys[username]).then(userKey =>
@@ -141,13 +141,13 @@ export default {
                 }
               }
 
-              return Promise.all(promises);
+              return Ember.RSVP.Promise.all(promises);
             })
             .catch(username => {
               bootbox.alert(
                 I18n.t("encrypt.composer.user_has_no_key", { username })
               );
-              return Promise.reject(username);
+              return Ember.RSVP.Promise.reject(username);
             })
         );
 
@@ -156,7 +156,7 @@ export default {
         const p3 = p0.then(key => encrypt(key, reply));
 
         // Send user keys, title and reply encryption to the server.
-        return Promise.all([p1, p2, p3])
+        return Ember.RSVP.Promise.all([p1, p2, p3])
           .then(([keys, encTitle, encReply]) => {
             const userKeys = {};
             for (let i = 0; i < keys.length; ++i) {
@@ -167,7 +167,7 @@ export default {
             this.set("reply", encReply);
 
             const result = _super.call(this, ...arguments);
-            return Promise.all([p0, encTitle, userKeys, result]);
+            return Ember.RSVP.Promise.all([p0, encTitle, userKeys, result]);
           })
           .then(([key, encTitle, userKeys, result]) => {
             const topicId = result.responseJson.post.topic_id;
diff --git a/assets/javascripts/discourse/initializers/hook-draft.js.es6 b/assets/javascripts/discourse/initializers/hook-draft.js.es6
index 73c08c9..3c96dcd 100644
--- a/assets/javascripts/discourse/initializers/hook-draft.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-draft.js.es6
@@ -45,11 +45,13 @@ export default {
         }
 
         if (encTitle && encReply) {
-          return Promise.all([encTitle, encReply]).then(([title, reply]) => {
-            data.title = title;
-            data.reply = reply;
-            return _super.call(this, ...arguments);
-          });
+          return Ember.RSVP.Promise.all([encTitle, encReply]).then(
+            ([title, reply]) => {
+              data.title = title;
+              data.reply = reply;
+              return _super.call(this, ...arguments);
+            }
+          );
         }
 
         return _super.call(this, ...arguments);
diff --git a/assets/javascripts/discourse/initializers/hook-invite.js.es6 b/assets/javascripts/discourse/initializers/hook-invite.js.es6
index dd8b11e..92e04ec 100644
--- a/assets/javascripts/discourse/initializers/hook-invite.js.es6
+++ b/as

GitHub

1 Like