2015-08-12 00:27:07 +08:00
|
|
|
import { present } from 'helpers/qunit-helpers';
|
2016-04-01 05:33:25 +08:00
|
|
|
import ApiKey from 'admin/models/api-key';
|
2015-08-12 00:27:07 +08:00
|
|
|
|
2013-10-23 03:53:08 +08:00
|
|
|
module("Discourse.ApiKey");
|
|
|
|
|
|
|
|
test('create', function() {
|
2016-04-01 05:33:25 +08:00
|
|
|
var apiKey = ApiKey.create({id: 123, user: {id: 345}});
|
2013-10-23 03:53:08 +08:00
|
|
|
|
|
|
|
present(apiKey, 'it creates the api key');
|
|
|
|
present(apiKey.get('user'), 'it creates the user inside');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
asyncTestDiscourse('find', function() {
|
2014-07-31 06:56:01 +08:00
|
|
|
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
2016-04-01 05:33:25 +08:00
|
|
|
ApiKey.find().then(function() {
|
2013-10-23 03:53:08 +08:00
|
|
|
start();
|
|
|
|
ok(Discourse.ajax.calledWith("/admin/api"), "it GETs the keys");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTestDiscourse('generateMasterKey', function() {
|
2014-07-31 06:56:01 +08:00
|
|
|
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {}}));
|
2016-04-01 05:33:25 +08:00
|
|
|
ApiKey.generateMasterKey().then(function() {
|
2013-10-23 03:53:08 +08:00
|
|
|
start();
|
|
|
|
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'POST'}), "it POSTs to create a master key");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTestDiscourse('regenerate', function() {
|
2016-04-01 05:33:25 +08:00
|
|
|
var apiKey = ApiKey.create({id: 3456});
|
2013-10-23 03:53:08 +08:00
|
|
|
|
2014-07-31 06:56:01 +08:00
|
|
|
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 3456}}));
|
2013-10-23 03:53:08 +08:00
|
|
|
apiKey.regenerate().then(function() {
|
|
|
|
start();
|
|
|
|
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'PUT', data: {id: 3456}}), "it PUTs the key");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
asyncTestDiscourse('revoke', function() {
|
2016-04-01 05:33:25 +08:00
|
|
|
var apiKey = ApiKey.create({id: 3456});
|
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
|
|
|
apiKey.revoke().then(function() {
|
|
|
|
start();
|
|
|
|
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'DELETE', data: {id: 3456}}), "it DELETES the key");
|
|
|
|
});
|
2014-07-31 06:56:01 +08:00
|
|
|
});
|