DEV: Reset all cached keys before running tests (#154)

DEV: Reset all cached keys before running tests (#154)

diff --git a/assets/javascripts/lib/discourse.js b/assets/javascripts/lib/discourse.js
index dbb84ec..3dbbf1e 100644
--- a/assets/javascripts/lib/discourse.js
+++ b/assets/javascripts/lib/discourse.js
@@ -76,14 +76,26 @@ class TopicTitle {
 }
 
 /**
- * Resets loaded user identity
+ * Resets loaded keys
  */
-export function resetUserIdentity() {
+export function resetEncrypt() {
   if (!isTesting()) {
-    throw new Error("`resetUserIdentity` can be called from tests only");
+    throw new Error("`resetEncrypt` can be called from tests only");
   }
 
   userIdentity = null;
+
+  for (const key in topicKeys) {
+    if (topicKeys.hasOwnProperty(key)) {
+      delete topicKeys[key];
+    }
+  }
+
+  for (const key in topicTitles) {
+    if (topicTitles.hasOwnProperty(key)) {
+      delete topicTitles[key];
+    }
+  }
 }
 
 /**
diff --git a/test/javascripts/acceptance/encrypt-test.js b/test/javascripts/acceptance/encrypt-test.js
index 25901d7..a8c4c35 100644
--- a/test/javascripts/acceptance/encrypt-test.js
+++ b/test/javascripts/acceptance/encrypt-test.js
@@ -11,7 +11,7 @@ import EncryptLibDiscourse, {
   ENCRYPT_ENABLED,
   getEncryptionStatus,
   getIdentity,
-  resetUserIdentity,
+  resetEncrypt,
 } from "discourse/plugins/discourse-encrypt/lib/discourse";
 import {
   encrypt,
@@ -170,7 +170,7 @@ acceptance("Encrypt", function (needs) {
       return this.send_(...arguments);
     };
 
-    resetUserIdentity();
+    resetEncrypt();
   });
 
   needs.hooks.afterEach(() => {

GitHub sha: 57b69c29034250264ee1327ea842db27932bc1d3

This commit appears in #154 which was approved by CvX. It was merged by udan11.