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

34 lines
1.2 KiB
Plaintext
Raw Normal View History

import { blank, present } from 'helpers/qunit-helpers';
import AdminUser from 'admin/models/admin-user';
import ApiKey from 'admin/models/api-key';
2013-10-23 03:53:08 +08:00
module("Discourse.AdminUser");
2013-10-23 03:53:08 +08:00
asyncTestDiscourse('generate key', function() {
2014-07-31 06:56:01 +08:00
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 1234, key: 'asdfasdf'}}));
2013-10-23 03:53:08 +08:00
var adminUser = AdminUser.create({id: 333});
2013-10-23 03:53:08 +08:00
blank(adminUser.get('api_key'), 'it has no api key by default');
adminUser.generateApiKey().then(function() {
start();
ok(Discourse.ajax.calledWith("/admin/users/333/generate_api_key", { type: 'POST' }), "it POSTed to the url");
present(adminUser.get('api_key'), 'it has an api_key now');
});
});
asyncTestDiscourse('revoke key', function() {
var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}),
adminUser = AdminUser.create({id: 333, api_key: apiKey});
2013-10-23 03:53:08 +08:00
2014-07-31 06:56:01 +08:00
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve());
2013-10-23 03:53:08 +08:00
equal(adminUser.get('api_key'), apiKey, 'it has the api key in the beginning');
adminUser.revokeApiKey().then(function() {
start();
ok(Discourse.ajax.calledWith("/admin/users/333/revoke_api_key", { type: 'DELETE' }), "it DELETEd to the url");
blank(adminUser.get('api_key'), 'it cleared the api_key');
});
2014-07-31 06:56:01 +08:00
});