mirror of
https://github.com/hanzoai/forum.git
synced 2026-09-30 21:51:19 +00:00
`discourse-common` was created in the past to share logic between the 'wizard' app and the main 'discourse' app. Since then, the wizard has been consolidated into the main app, so the separation of `discourse-common` is no longer useful. This commit moves `discourse-common/(lib|utils)/*` into `discourse/lib/*`, adds shims for the imports, and updates existing uses in core.
76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
import { getOwner } from "@ember/owner";
|
|
import { setupTest } from "ember-qunit";
|
|
import { module, test } from "qunit";
|
|
import { cloneJSON } from "discourse/lib/object";
|
|
import UserBadge from "discourse/models/user-badge";
|
|
import badgeFixtures from "discourse/tests/fixtures/user-badges";
|
|
|
|
module("Unit | Model | user-badge", function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
test("createFromJson single", function (assert) {
|
|
const userBadge = UserBadge.createFromJson(
|
|
cloneJSON(badgeFixtures["/user_badges"])
|
|
);
|
|
assert.false(Array.isArray(userBadge), "does not return an array");
|
|
assert.strictEqual(
|
|
userBadge.badge.name,
|
|
"Badge 2",
|
|
"badge reference is set"
|
|
);
|
|
assert.strictEqual(
|
|
userBadge.badge.badge_type.name,
|
|
"Silver 2",
|
|
"badge.badge_type reference is set"
|
|
);
|
|
assert.strictEqual(
|
|
userBadge.granted_by.username,
|
|
"anne3",
|
|
"granted_by reference is set"
|
|
);
|
|
});
|
|
|
|
test("createFromJson array", function (assert) {
|
|
const userBadges = UserBadge.createFromJson(
|
|
cloneJSON(badgeFixtures["/user-badges/:username"])
|
|
);
|
|
assert.true(Array.isArray(userBadges), "returns an array");
|
|
assert.strictEqual(
|
|
userBadges[0].granted_by,
|
|
undefined,
|
|
"granted_by reference is not set when null"
|
|
);
|
|
});
|
|
|
|
test("findByUsername", async function (assert) {
|
|
const badges = await UserBadge.findByUsername("anne3");
|
|
assert.true(Array.isArray(badges), "returns an array");
|
|
});
|
|
|
|
test("findByBadgeId", async function (assert) {
|
|
const badges = await UserBadge.findByBadgeId(880);
|
|
assert.true(Array.isArray(badges), "returns an array");
|
|
});
|
|
|
|
test("grant", async function (assert) {
|
|
const userBadge = await UserBadge.grant(1, "username");
|
|
assert.false(Array.isArray(userBadge), "does not return an array");
|
|
});
|
|
|
|
test("revoke", async function (assert) {
|
|
const store = getOwner(this).lookup("service:store");
|
|
const userBadge = store.createRecord("user-badge", { id: 1 });
|
|
const result = await userBadge.revoke();
|
|
assert.deepEqual(result, { success: true });
|
|
});
|
|
|
|
test("favorite", async function (assert) {
|
|
const store = getOwner(this).lookup("service:store");
|
|
const userBadge = store.createRecord("user-badge", { id: 1 });
|
|
assert.strictEqual(userBadge.is_favorite, undefined);
|
|
|
|
await userBadge.favorite();
|
|
assert.true(userBadge.is_favorite);
|
|
});
|
|
});
|