DEV: Fix a leaky test (#13559)

DEV: Fix a leaky test (#13559)

The error was:

↪ Unit | Model | topic::recover [✔]
↪ Unit | Utility | emoji::emojiUnescape [✔]
↪ Unit | Utility | pretty-text::quoting a quote [✔]
↪ Unit | Utility | click-track::routes to internal urlsUnhandled request in test environment: /forum/t/1234/recover (PUT)
Error: Unhandled request in test environment: /forum/t/1234/recover (PUT)
    at Pretender.server.unhandledRequest (discourse/tests/setup-tests:173:15)
    at Pretender.handleRequest (pretender:400:14)
    at FakeRequest.send (pretender:169:21)
    at Object.send (jquery:10100:10)
    at Function.ajax (jquery:9683:15)
    at performAjax (discourse/app/lib/ajax:174:19)
    at eval (discourse/app/lib/ajax:183:11)
    at invokeCallback (ember:63104:17)
    at publish (ember:63087:9)
    at eval (ember:57463:16)
 [✘]
  • DEV: Don’t duplicate a function
diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js
index c27f4ba..b86f9e5 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic.js
@@ -6,7 +6,7 @@ import { isEmpty, isPresent } from "@ember/utils";
 import { later, next, schedule } from "@ember/runloop";
 import { AUTO_DELETE_PREFERENCES } from "discourse/models/bookmark";
 import Composer from "discourse/models/composer";
-import EmberObject from "@ember/object";
+import EmberObject, { action } from "@ember/object";
 import I18n from "I18n";
 import Post from "discourse/models/post";
 import { Promise } from "rsvp";
@@ -949,10 +949,6 @@ export default Controller.extend(bufferedProperty("model"), {
       });
     },
 
-    recoverTopic() {
-      this.model.recover();
-    },
-
     makeBanner() {
       this.model.makeBanner();
     },
@@ -1424,6 +1420,7 @@ export default Controller.extend(bufferedProperty("model"), {
     return spinnerHTML;
   },
 
+  @action
   recoverTopic() {
     this.model.recover();
   },
diff --git a/app/assets/javascripts/discourse/tests/unit/models/topic-test.js b/app/assets/javascripts/discourse/tests/unit/models/topic-test.js
index f903fd6..45c5f9a 100644
--- a/app/assets/javascripts/discourse/tests/unit/models/topic-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/models/topic-test.js
@@ -109,7 +109,7 @@ discourseModule("Unit | Model | topic", function () {
     assert.equal(topic.get("category"), category);
   });
 
-  test("recover", function (assert) {
+  test("recover", async function (assert) {
     const user = User.create({ username: "eviltrout" });
     const topic = Topic.create({
       id: 1234,
@@ -117,7 +117,8 @@ discourseModule("Unit | Model | topic", function () {
       deleted_by: user,
     });
 
-    topic.recover();
+    await topic.recover();
+
     assert.blank(topic.get("deleted_at"), "it clears deleted_at");
     assert.blank(topic.get("deleted_by"), "it clears deleted_by");
   });

GitHub sha: 5af0636d831013f57b4c4cd9d09f7a89d378bf54

This commit appears in #13559 which was approved by SamSaffron. It was merged by SamSaffron.