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
|
|
|
|
2015-08-18 21:24:09 -04:00
|
|
|
module("model:user-badge");
|
|
|
|
|
2014-03-19 10:27:21 -04:00
|
|
|
test('createFromJson single', function() {
|
2016-06-30 13:55:44 -04:00
|
|
|
const userBadge = UserBadge.createFromJson(badgeFixtures['/user_badges']);
|
2014-03-05 07:52:20 -05:00
|
|
|
ok(!Array.isArray(userBadge), "does not return an array");
|
|
|
|
equal(userBadge.get('badge.name'), "Badge 2", "badge reference is set");
|
|
|
|
equal(userBadge.get('badge.badge_type.name'), "Silver 2", "badge.badge_type reference is set");
|
|
|
|
equal(userBadge.get('granted_by.username'), "anne3", "granted_by reference is set");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('createFromJson array', function() {
|
2016-06-30 13:55:44 -04:00
|
|
|
const userBadges = UserBadge.createFromJson(badgeFixtures['/user-badges/:username']);
|
2014-03-05 07:52:20 -05:00
|
|
|
ok(Array.isArray(userBadges), "returns an array");
|
|
|
|
equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null");
|
|
|
|
});
|
2014-03-19 10:27:21 -04:00
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
test('findByUsername', function() {
|
|
|
|
return UserBadge.findByUsername("anne3").then(function(badges) {
|
2014-03-19 10:27:21 -04:00
|
|
|
ok(Array.isArray(badges), "returns an array");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
test('findByBadgeId', function() {
|
|
|
|
return UserBadge.findByBadgeId(880).then(function(badges) {
|
2014-04-16 10:56:11 -04:00
|
|
|
ok(Array.isArray(badges), "returns an array");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
test('grant', function() {
|
|
|
|
return UserBadge.grant(1, "username").then(function(userBadge) {
|
2014-03-19 10:27:21 -04:00
|
|
|
ok(!Array.isArray(userBadge), "does not return an array");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('revoke', function() {
|
2016-06-30 13:55:44 -04:00
|
|
|
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();
|
2014-03-19 10:27:21 -04:00
|
|
|
});
|