discourse/test/javascripts/admin/models/api-key-test.js.es6

48 lines
1.5 KiB
Text
Raw Normal View History

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