DEV: Make tests discoverable

DEV: Make tests discoverable

diff --git a/test/acceptance/encrypt-test.js b/test/acceptance/encrypt-test.js
deleted file mode 100644
index 35db187..0000000
--- a/test/acceptance/encrypt-test.js
+++ /dev/null
@@ -1,488 +0,0 @@
-import I18n from "I18n";
-import User from "discourse/models/user";
-import {
-  deleteDb,
-  loadDbIdentity,
-  saveDbIdentity,
-} from "discourse/plugins/discourse-encrypt/lib/database";
-import EncryptLibDiscourse, {
-  ENCRYPT_ACTIVE,
-  ENCRYPT_DISABLED,
-  ENCRYPT_ENABLED,
-  getEncryptionStatus,
-  getIdentity,
-} from "discourse/plugins/discourse-encrypt/lib/discourse";
-import {
-  encrypt,
-  exportIdentity,
-  exportKey,
-  generateIdentity,
-  generateKey,
-} from "discourse/plugins/discourse-encrypt/lib/protocol";
-import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types";
-import { default as userFixtures } from "discourse/tests/fixtures/user-fixtures";
-import { parsePostData } from "discourse/tests/helpers/create-pretender";
-import {
-  acceptance,
-  updateCurrentUser,
-} from "discourse/tests/helpers/qunit-helpers";
-import selectKit from "discourse/tests/helpers/select-kit-helper";
-import { Promise } from "rsvp";
-import sinon from "sinon";
-
-/*
- * Checks if a string is not contained in a string.
- *
- * @param haystack
- * @param needle
- * @param message
- */
-QUnit.assert.notContains = function notContains(haystack, needle, message) {
-  this.pushResult({
-    result: haystack.indexOf(needle) === -1,
-    actual: haystack,
-    expected: "not to contain " + needle,
-    message,
-  });
-};
-
-/**
- * @var PASSPHRASE Secret passphrase used for testing purposes.
- */
-const PASSPHRASE = "curren7U$er.pa$$Phr4se";
-
-/**
- * @var PLAINTEXT Constant string that is used to check for plaintext leakage.
- */
-const PLAINTEXT = "!PL41N73X7!";
-
-/**
- * @var keys User keys.
- */
-const keys = {};
-
-/**
- * @var globalAssert Global assert instance used to report plaintext leakage.
- */
-let globalAssert;
-
-/**
- * @var requests Request URLs intercepted by the leak checker.
- */
-let requests = [];
-
-/**
- * Sets up encryption.
- *
- * @param status
- */
-async function setEncryptionStatus(status) {
-  const user = User.current();
-
-  // Resetting IndexedDB.
-  try {
-    await deleteDb();
-  } catch (e) {}
-
-  // Generating a new key pair if enabling or creating a dummy one if disabling.
-  let identity = {};
-  let exported = {};
-  let exportedPrivate;
-  if (status !== ENCRYPT_DISABLED) {
-    identity = await generateIdentity();
-    exported = await exportIdentity(identity, PASSPHRASE);
-    exportedPrivate = JSON.stringify({ passphrase: exported.private });
-  }
-
-  // Overwriting server-side fields.
-  user.set("encrypt_public", exported.public);
-  user.set("encrypt_private", exportedPrivate);
-
-  // Setting the appropriate custom fields is not always enough (i.e. if user
-  // navigates to preferences).
-  /* global server */
-  server.get("/u/eviltrout.json", () => {
-    const json = userFixtures["/u/eviltrout.json"];
-    json.user.can_edit = true;
-    json.user.encrypt_public = exported.public;
-    json.user.encrypt_private = exportedPrivate;
-    return [200, { "Content-Type": "application/json" }, json];
-  });
-
-  // Activating encryption on client-side.
-  if (status === ENCRYPT_ACTIVE) {
-    await saveDbIdentity(identity);
-  }
-
-  keys[user.username] = exported.public;
-  return identity;
-}
-
-/**
- * Executes the given function and waits until current encryption status
- * changes or given waiter becomes true.
- *
- * @param statusOrWaiter
- * @param func
- */
-async function wait(statusOrWaiter, func) {
-  const waiter =
-    typeof statusOrWaiter === "function"
-      ? statusOrWaiter
-      : () =>
-          getEncryptionStatus(User.current(), Discourse.SiteSettings) ===
-          statusOrWaiter;
-
-  try {
-    Ember.Test.registerWaiter(waiter);
-    await func();
-  } catch (e) {
-    // eslint-disable-next-line no-console
-    console.error(`Caught exception while waiting: ${e.message}`, e);
-  } finally {
-    Ember.Test.unregisterWaiter(waiter);
-  }
-}
-
-acceptance("Encrypt", function (needs) {
-  needs.user();
-  needs.settings({
-    encrypt_enabled: true,
-    encrypt_groups: "",
-    encrypt_pms_default: true,
-  });
-
-  needs.hooks.beforeEach(() => {
-    sinon.stub(EncryptLibDiscourse, "reload");
-
-    // Hook `XMLHttpRequest` to search for leaked plaintext.
-    XMLHttpRequest.prototype.send_ = XMLHttpRequest.prototype.send;
-    XMLHttpRequest.prototype.send = function (body) {
-      requests.push(this.url);
-      if (body && globalAssert) {
-        globalAssert.notContains(body, PLAINTEXT, "does not leak plaintext");
-        globalAssert.notContains(body, PASSPHRASE, "does not leak passphrase");
-      }
-      return this.send_(...arguments);
-    };
-  });
-
-  needs.hooks.afterEach(() => {
-    // Restore `XMLHttpRequest`.
-    XMLHttpRequest.prototype.send = XMLHttpRequest.prototype.send_;
-    delete XMLHttpRequest.prototype.send_;
-  });
-
-  needs.pretender((server, helper) => {
-    server.get("/encrypt/user", (request) => {
-      const response = {};
-      request.queryParams["usernames"].forEach((u) => (response[u] = keys[u]));
-      return helper.response(response);
-    });
-
-    server.get("/encrypt/posts", () => {
-      return helper.response({ posts: [], topics: [] });
-    });
-
-    server.put("/encrypt/post", () => {
-      return helper.response({});
-    });
-  });
-
-  test("meta: leak checker works", async (assert) => {
-    globalAssert = { notContains: () => assert.ok(true) };
-
-    await visit("/");
-    await click("#create-topic");
-
-    requests = [];
-    await fillIn("#reply-title", `Some hidden message ${PLAINTEXT}`);
-    await fillIn(".d-editor-input", `Hello, world! ${PLAINTEXT}`.repeat(42));
-    await wait(
-      () => requests.includes("/posts"),
-      () => click("button.create")
-    );
-
-    globalAssert = null;
-  });
-
-  test("posting does not leak plaintext", async (assert) => {
-    await setEncryptionStatus(ENCRYPT_ACTIVE);
-    globalAssert = assert;
-
-    /* global server */
-    server.get("/u/search/users", () => {
-      return [
-        200,
-        { "Content-Type": "application/json" },
-        {
-          users: [
-            {
-              username: "eviltrout",
-              name: "eviltrout",
-              avatar_template: "/images/avatar.png",
-            },
-          ],
-        },
-      ];
-    });
-
-    server.post("/posts", (request) => {
-      const body = parsePostData(request.requestBody);
-
-      assert.equal(body.raw, I18n.t("encrypt.encrypted_post"));
-      assert.equal(body.title, I18n.t("encrypt.encrypted_topic_title"));
-      assert.equal(body.archetype, "private_message");
-      assert.equal(body.target_recipients, "eviltrout");
-      assert.equal(body.draft_key, "new_topic");
-      assert.equal(body.is_encrypted, "true");
-      assert.ok(body.encrypted_title.startsWith("1$"));
-      assert.ok(body.encrypted_raw.startsWith("1$"));
-      assert.ok(JSON.parse(body.encrypted_keys).eviltrout);
-
-      return [
-        200,
-        { "Content-Type": "application/json" },
-        { action: "create_post", post: { topic_id: 34 } },
-      ];
-    });
-
-    const composerActions = selectKit(".composer-actions");
-
-    await visit("/");
-    await click("#create-topic");
-    await composerActions.expand();
-    await composerActions.selectRowByValue("reply_as_private_message");
-
-    if (find(".users-input").text().trim() !== "") {
-      globalAssert = null;
-      throw new Error("Another test is leaking composer state");
-    }
-
-    // simulate selecting from autocomplete suggestions
-    await fillIn("#private-message-users .filter-input", "evilt");
-    await keyEvent("#private-message-users .filter-input", "keydown", 13);
-
-    requests = [];
-    await wait(
-      () => requests.includes("/draft.json"),
-      async () => {

[... diff too long, it was truncated ...]

GitHub sha: e2485cf7f197b39f1c46d3af5e58ccceb8e10b02

This commit appears in #104 which was approved by eviltrout. It was merged by udan11.