discourse/test/javascripts/models/user-badge-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-08-19 09:24:09 +08:00
import UserBadge from "discourse/models/user-badge";
2016-07-01 01:55:44 +08:00
import badgeFixtures from "fixtures/user-badges";
2014-03-05 20:52:20 +08:00
2017-06-15 01:57:58 +08:00
QUnit.module("model:user-badge");
2015-08-19 09:24:09 +08:00
2017-06-15 01:57:58 +08:00
QUnit.test("createFromJson single", assert => {
2016-07-01 01:55:44 +08:00
const userBadge = UserBadge.createFromJson(badgeFixtures["/user_badges"]);
2017-06-15 01:57:58 +08:00
assert.ok(!Array.isArray(userBadge), "does not return an array");
assert.equal(
userBadge.get("badge.name"),
"Badge 2",
"badge reference is set"
);
assert.equal(
userBadge.get("badge.badge_type.name"),
"Silver 2",
"badge.badge_type reference is set"
);
assert.equal(
userBadge.get("granted_by.username"),
"anne3",
"granted_by reference is set"
);
2014-03-05 20:52:20 +08:00
});
2017-06-15 01:57:58 +08:00
QUnit.test("createFromJson array", assert => {
2016-07-01 01:55:44 +08:00
const userBadges = UserBadge.createFromJson(
badgeFixtures["/user-badges/:username"]
);
2017-06-15 01:57:58 +08:00
assert.ok(Array.isArray(userBadges), "returns an array");
assert.equal(
userBadges[0].get("granted_by"),
null,
"granted_by reference is not set when null"
);
2014-03-05 20:52:20 +08:00
});
QUnit.test("findByUsername", async assert => {
const badges = await UserBadge.findByUsername("anne3");
assert.ok(Array.isArray(badges), "returns an array");
});
QUnit.test("findByBadgeId", async assert => {
const badges = await UserBadge.findByBadgeId(880);
assert.ok(Array.isArray(badges), "returns an array");
2014-04-16 22:56:11 +08:00
});
QUnit.test("grant", async assert => {
const userBadge = await UserBadge.grant(1, "username");
assert.ok(!Array.isArray(userBadge), "does not return an array");
});
QUnit.test("revoke", async assert => {
2017-06-15 01:57:58 +08:00
assert.expect(0);
2015-08-19 09:24:09 +08:00
const userBadge = UserBadge.create({ id: 1 });
await userBadge.revoke();
2017-06-15 01:57:58 +08:00
});