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

43 lines
1.4 KiB
Plaintext
Raw Normal View History

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