mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
REFACTOR: Remove Discourse.Ajax
This commit is contained in:
@ -2,32 +2,23 @@ import { blank, present } from 'helpers/qunit-helpers';
|
||||
import AdminUser from 'admin/models/admin-user';
|
||||
import ApiKey from 'admin/models/api-key';
|
||||
|
||||
module("Discourse.AdminUser");
|
||||
|
||||
asyncTestDiscourse('generate key', function() {
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {id: 1234, key: 'asdfasdf'}}));
|
||||
module("model:admin-user");
|
||||
|
||||
test('generate key', function() {
|
||||
var adminUser = AdminUser.create({id: 333});
|
||||
|
||||
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() {
|
||||
test('revoke key', function() {
|
||||
|
||||
var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}),
|
||||
adminUser = AdminUser.create({id: 333, api_key: apiKey});
|
||||
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve());
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
@ -1,48 +0,0 @@
|
||||
import { present } from 'helpers/qunit-helpers';
|
||||
import ApiKey from 'admin/models/api-key';
|
||||
|
||||
module("Discourse.ApiKey");
|
||||
|
||||
test('create', function() {
|
||||
var apiKey = 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() {
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve([]));
|
||||
ApiKey.find().then(function() {
|
||||
start();
|
||||
ok(Discourse.ajax.calledWith("/admin/api"), "it GETs the keys");
|
||||
});
|
||||
});
|
||||
|
||||
asyncTestDiscourse('generateMasterKey', function() {
|
||||
sandbox.stub(Discourse, 'ajax').returns(Ember.RSVP.resolve({api_key: {}}));
|
||||
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 = ApiKey.create({id: 3456});
|
||||
|
||||
sandbox.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 = ApiKey.create({id: 3456});
|
||||
|
||||
sandbox.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");
|
||||
});
|
||||
});
|
@ -1,21 +0,0 @@
|
||||
import FlaggedPost from 'admin/models/flagged-post';
|
||||
|
||||
module("Discourse.FlaggedPost");
|
||||
|
||||
test('delete first post', function() {
|
||||
sandbox.stub(Discourse, 'ajax');
|
||||
|
||||
FlaggedPost.create({ id: 1, topic_id: 2, post_number: 1 })
|
||||
.deletePost();
|
||||
|
||||
ok(Discourse.ajax.calledWith("/t/2", { type: 'DELETE', cache: false }), "it deleted the topic");
|
||||
});
|
||||
|
||||
test('delete second post', function() {
|
||||
sandbox.stub(Discourse, 'ajax');
|
||||
|
||||
FlaggedPost.create({ id: 1, topic_id: 2, post_number: 2 })
|
||||
.deletePost();
|
||||
|
||||
ok(Discourse.ajax.calledWith("/posts/1", { type: 'DELETE', cache: false }), "it deleted the post");
|
||||
});
|
Reference in New Issue
Block a user