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

61 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import UserBadge from "discourse/models/user-badge";
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
2018-06-15 23:03:24 +08:00
QUnit.test("createFromJson single", assert => {
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");
2018-06-15 23:03:24 +08:00
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
});
2018-06-15 23:03:24 +08:00
QUnit.test("createFromJson array", assert => {
const userBadges = UserBadge.createFromJson(
badgeFixtures["/user-badges/:username"]
);
2017-06-15 01:57:58 +08:00
assert.ok(Array.isArray(userBadges), "returns an array");
2018-06-15 23:03:24 +08:00
assert.equal(
userBadges[0].get("granted_by"),
null,
"granted_by reference is not set when null"
);
2014-03-05 20:52:20 +08:00
});
2018-06-15 23:03:24 +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");
});
});
2018-06-15 23:03:24 +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
});
});
2018-06-15 23:03:24 +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");
});
});
2018-06-15 23:03:24 +08:00
QUnit.test("revoke", assert => {
2017-06-15 01:57:58 +08:00
assert.expect(0);
2018-06-15 23:03:24 +08:00
const userBadge = UserBadge.create({ id: 1 });
2016-07-01 01:55:44 +08:00
return userBadge.revoke();
2018-06-15 23:03:24 +08:00
});