2018-06-15 11:03:24 -04:00
|
|
|
import AdminUser from "admin/models/admin-user";
|
|
|
|
import ApiKey from "admin/models/api-key";
|
2013-10-22 15:53:08 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("model:admin-user");
|
2013-10-22 15:53:08 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("generate key", function(assert) {
|
2016-11-08 14:29:50 -05:00
|
|
|
assert.expect(2);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
var adminUser = AdminUser.create({ id: 333 });
|
|
|
|
assert.ok(!adminUser.get("api_key"), "it has no api key by default");
|
2016-11-08 14:29:50 -05:00
|
|
|
return adminUser.generateApiKey().then(function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.present(adminUser.get("api_key"), "it has an api_key now");
|
2013-10-22 15:53:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("revoke key", function(assert) {
|
2016-11-08 14:29:50 -05:00
|
|
|
assert.expect(2);
|
2013-10-22 15:53:08 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
var apiKey = ApiKey.create({ id: 1234, key: "asdfasdf" }),
|
|
|
|
adminUser = AdminUser.create({ id: 333, api_key: apiKey });
|
2013-10-22 15:53:08 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
adminUser.get("api_key"),
|
|
|
|
apiKey,
|
|
|
|
"it has the api key in the beginning"
|
|
|
|
);
|
2016-11-08 14:29:50 -05:00
|
|
|
return adminUser.revokeApiKey().then(function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.blank(adminUser.get("api_key"), "it cleared the api_key");
|
2013-10-22 15:53:08 -04:00
|
|
|
});
|
2017-09-12 17:07:42 -04:00
|
|
|
});
|