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
|
|
|
});
|
2014-03-19 22:27:21 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("findByUsername", assert => {
|
2016-07-01 01:55:44 +08:00
|
|
|
return UserBadge.findByUsername("anne3").then(function(badges) {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(Array.isArray(badges), "returns an array");
|
2014-03-19 22:27:21 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("findByBadgeId", assert => {
|
2016-07-01 01:55:44 +08:00
|
|
|
return UserBadge.findByBadgeId(880).then(function(badges) {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(Array.isArray(badges), "returns an array");
|
2014-04-16 22:56:11 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("grant", assert => {
|
2016-07-01 01:55:44 +08:00
|
|
|
return UserBadge.grant(1, "username").then(function(userBadge) {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.ok(!Array.isArray(userBadge), "does not return an array");
|
2014-03-19 22:27:21 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("revoke", assert => {
|
|
|
|
assert.expect(0);
|
2015-08-19 09:24:09 +08:00
|
|
|
const userBadge = UserBadge.create({ id: 1 });
|
2016-07-01 01:55:44 +08:00
|
|
|
return userBadge.revoke();
|
2017-06-15 01:57:58 +08:00
|
|
|
});
|