mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
Support for per-user API keys
This commit is contained in:
45
test/javascripts/admin/models/api_key_test.js
Normal file
45
test/javascripts/admin/models/api_key_test.js
Normal file
@ -0,0 +1,45 @@
|
||||
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() {
|
||||
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
||||
Discourse.ApiKey.find().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api"), "it GETs the keys");
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse('generateMasterKey', function() {
|
||||
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
||||
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});
|
||||
|
||||
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 3456}}));
|
||||
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});
|
||||
|
||||
this.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
||||
apiKey.revoke().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api/key", {type: 'DELETE', data: {id: 3456}}), "it DELETES the key");
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user