This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/models/email-log-test.js
Jarek Radosz a17d54d0bf
DEV: De-arrowify tests (#11068)
Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks.

Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps.

It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli.

(I might later add a custom rule to eslint-discourse-ember to enforce this)
2020-10-30 17:37:32 +01:00

36 lines
964 B
JavaScript

import { test, module } from "qunit";
import EmailLog from "admin/models/email-log";
import { setPrefix } from "discourse-common/lib/get-url";
module("model:email-log");
test("create", function (assert) {
assert.ok(EmailLog.create(), "it can be created without arguments");
});
test("subfolder support", function (assert) {
setPrefix("/forum");
const attrs = {
id: 60,
to_address: "wikiman@asdf.com",
email_type: "user_linked",
user_id: 9,
created_at: "2018-08-08T17:21:52.022Z",
post_url: "/t/some-pro-tips-for-you/41/5",
post_description: "Some Pro Tips For You",
bounced: false,
user: {
id: 9,
username: "wikiman",
avatar_template:
"/forum/letter_avatar_proxy/v2/letter/w/dfb087/{size}.png",
},
};
const emailLog = EmailLog.create(attrs);
assert.equal(
emailLog.get("post_url"),
"/forum/t/some-pro-tips-for-you/41/5",
"includes the subfolder in the post url"
);
});