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

52 lines
1.9 KiB
Plaintext
Raw Normal View History

2015-08-18 21:24:09 -04:00
import Badge from 'discourse/models/badge';
module("model:badge");
2014-03-05 07:52:20 -05:00
test('newBadge', function() {
2015-08-18 21:24:09 -04:00
const badge1 = Badge.create({name: "New Badge"}),
badge2 = Badge.create({id: 1, name: "Old Badge"});
2014-03-05 07:52:20 -05:00
ok(badge1.get('newBadge'), "badges without ids are new");
ok(!badge2.get('newBadge'), "badges with ids are not new");
});
2014-05-21 03:22:42 -04:00
2014-03-05 07:52:20 -05:00
test('createFromJson array', function() {
2015-08-18 21:24:09 -04:00
const badgesJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]};
2014-03-05 07:52:20 -05:00
2015-08-18 21:24:09 -04:00
const badges = Badge.createFromJson(badgesJson);
2014-03-05 07:52:20 -05:00
ok(Array.isArray(badges), "returns an array");
equal(badges[0].get('name'), "Badge 1", "badge details are set");
equal(badges[0].get('badge_type.name'), "Silver 1", "badge_type reference is set");
});
test('createFromJson single', function() {
2015-08-18 21:24:09 -04:00
const badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}};
2014-03-05 07:52:20 -05:00
2015-08-18 21:24:09 -04:00
const badge = Badge.createFromJson(badgeJson);
2014-03-05 07:52:20 -05:00
ok(!Array.isArray(badge), "does not returns an array");
});
test('updateFromJson', function() {
2015-08-18 21:24:09 -04:00
const badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}};
const badge = Badge.create({name: "Badge 1"});
2014-03-05 07:52:20 -05:00
badge.updateFromJson(badgeJson);
equal(badge.get('id'), 1126, "id is set");
equal(badge.get('badge_type.name'), "Silver 1", "badge_type reference is set");
});
test('save', function() {
2016-06-30 13:55:44 -04:00
expect(0);
2015-08-18 21:24:09 -04:00
const badge = Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1});
2016-06-30 13:55:44 -04:00
return badge.save(["name", "description", "badge_type_id"]);
2014-03-05 07:52:20 -05:00
});
test('destroy', function() {
2016-06-30 13:55:44 -04:00
expect(0);
2015-08-18 21:24:09 -04:00
const badge = Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1});
2014-03-05 07:52:20 -05:00
badge.destroy();
badge.set('id', 3);
2016-06-30 13:55:44 -04:00
return badge.destroy();
2014-03-05 07:52:20 -05:00
});