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-18 21:24:09 -04:00
import UserBadge from "discourse/models/user-badge";
2016-06-30 13:55:44 -04:00
import badgeFixtures from "fixtures/user-badges";
2014-03-05 07:52:20 -05:00
2017-06-14 13:57:58 -04:00
QUnit.module("model:user-badge");
2015-08-18 21:24:09 -04:00
2017-06-14 13:57:58 -04:00
QUnit.test("createFromJson single", assert => {
2016-06-30 13:55:44 -04:00
const userBadge = UserBadge.createFromJson(badgeFixtures["/user_badges"]);
2017-06-14 13:57:58 -04: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 07:52:20 -05:00
});
2017-06-14 13:57:58 -04:00
QUnit.test("createFromJson array", assert => {
2016-06-30 13:55:44 -04:00
const userBadges = UserBadge.createFromJson(
badgeFixtures["/user-badges/:username"]
);
2017-06-14 13:57:58 -04: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 07:52:20 -05: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 10:56:11 -04: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-14 13:57:58 -04:00
assert.expect(0);
2015-08-18 21:24:09 -04:00
const userBadge = UserBadge.create({ id: 1 });
await userBadge.revoke();
2017-06-14 13:57:58 -04:00
});