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