2015-08-12 00:27:07 +08:00
|
|
|
import { blank, present } from 'helpers/qunit-helpers';
|
2015-11-21 09:27:06 +08:00
|
|
|
import AdminUser from 'admin/models/admin-user';
|
|
|
|
import ApiKey from 'admin/models/api-key';
|
2013-10-23 03:53:08 +08:00
|
|
|
|
2016-07-01 01:55:44 +08:00
|
|
|
module("model:admin-user");
|
2013-10-23 03:53:08 +08:00
|
|
|
|
2016-11-09 03:29:50 +08:00
|
|
|
test('generate key', function(assert) {
|
|
|
|
assert.expect(2);
|
|
|
|
|
2015-11-21 09:27:06 +08:00
|
|
|
var adminUser = AdminUser.create({id: 333});
|
2016-11-09 03:29:50 +08:00
|
|
|
assert.ok(!adminUser.get('api_key'), 'it has no api key by default');
|
|
|
|
return adminUser.generateApiKey().then(function() {
|
2013-10-23 03:53:08 +08:00
|
|
|
present(adminUser.get('api_key'), 'it has an api_key now');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-09 03:29:50 +08:00
|
|
|
test('revoke key', function(assert) {
|
|
|
|
assert.expect(2);
|
2013-10-23 03:53:08 +08:00
|
|
|
|
2015-11-21 09:27:06 +08:00
|
|
|
var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}),
|
|
|
|
adminUser = AdminUser.create({id: 333, api_key: apiKey});
|
2013-10-23 03:53:08 +08:00
|
|
|
|
2016-11-09 03:29:50 +08:00
|
|
|
assert.equal(adminUser.get('api_key'), apiKey, 'it has the api key in the beginning');
|
|
|
|
return adminUser.revokeApiKey().then(function() {
|
2013-10-23 03:53:08 +08:00
|
|
|
blank(adminUser.get('api_key'), 'it cleared the api_key');
|
|
|
|
});
|
2014-07-31 06:56:01 +08:00
|
|
|
});
|