Skip to content

Commit

Permalink
fix(superadmin-checker): update to use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
szeist committed Sep 14, 2015
1 parent 5047806 commit 2f3badf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/superadmin-checker/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* jshint node: true */
/* jshint esnext: true */

'use strict';

var SuiteApi = require('../../api');
Expand All @@ -10,8 +13,10 @@ var Checker = function(requestId) {
Checker.prototype = {

isSuperadmin: function* (customerId, adminId) {
var admin = yield this._suiteApi.administrator.getAdministrator(customerId, adminId);
return !!admin.superadmin;
var admin = yield this._suiteApi.administrator.getAdministrator({ administrator_id: adminId },
{ customerId: customerId });

return !!admin.body.data.superadmin;
}

};
Expand Down
18 changes: 13 additions & 5 deletions lib/superadmin-checker/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* jshint node: true */
/* jshint esnext: true */
/* jshint mocha: true */

'use strict';

var expect = require('chai').expect;
Expand Down Expand Up @@ -41,20 +45,24 @@ describe('Admin checker', function() {


it('should returns with true if the admin is superadmin', function* () {
getAdministratorRespondWith({ superadmin: 1 });
getAdministratorRespondWith({ body: { data: { superadmin: 1 } } });

var result = yield Checker.isSuperadmin(adminIdentifierHash.customer_id, adminIdentifierHash.admin_id, requestId);
expect(result).to.eql(true);
expect(fakeSuiteApi.administrator.getAdministrator).calledWith(adminIdentifierHash.customer_id, adminIdentifierHash.admin_id);
expect(fakeSuiteApi.administrator.getAdministrator).calledWith(
{ administrator_id: adminIdentifierHash.admin_id },
{ customerId: adminIdentifierHash.customer_id });
});


it('should returns with false if the admin isnt superadmin', function* () {
getAdministratorRespondWith({ superadmin: 0 });
getAdministratorRespondWith({ body: { data: { superadmin: 0 } } });

var result = yield Checker.isSuperadmin(adminIdentifierHash.customer_id, adminIdentifierHash.admin_id);
var result = yield Checker.isSuperadmin(adminIdentifierHash.customer_id, adminIdentifierHash.admin_id, requestId);
expect(result).to.eql(false);
expect(fakeSuiteApiWithoutCache.administrator.getAdministrator).calledWith(adminIdentifierHash.customer_id, adminIdentifierHash.admin_id);
expect(fakeSuiteApi.administrator.getAdministrator).calledWith(
{ administrator_id: adminIdentifierHash.admin_id },
{ customerId: adminIdentifierHash.customer_id });
});


Expand Down

0 comments on commit 2f3badf

Please sign in to comment.