Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
Add docs and update tests to reflect everything correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Skukan committed Dec 14, 2016
1 parent b441dab commit 11cc87a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/resource/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,9 +1487,17 @@ Application.prototype.getAccountLinkingPolicy = function getApplicationAccountLi
return this.dataStore.getResource(this.accountLinkingPolicy.href, args.options, require('./AccountLinkingPolicy'), args.callback);
};

Application.prototype.getWebConfig = function getApplicationWebConfig(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.webConfig.href, args.options, require('./WebConfig'), args.callback);
/**
* Retrieves the application's {@link WebConfig}, which determines its behaviour
* regarding the ClientAPI. This resource cannot be expanded.
*
* @param {Function} callback
* The function that will be called when the query is finished, with the parameters
* (err, {@link WebConfig}).
*/
Application.prototype.getWebConfig = function getApplicationWebConfig(/* callback */) {
var args = utils.resolveArgs(arguments, ['callback'], true);
return this.dataStore.getResource(this.webConfig.href, null, require('./WebConfig'), args.callback);
};

module.exports = Application;
51 changes: 51 additions & 0 deletions lib/resource/WebConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,73 @@
var InstanceResource = require('./InstanceResource');
var utils = require('../utils');

/**
* @class WebConfig
*
* @augments {InstanceResource}
*
* @description
*
* Encapsulates an WebConfig resource, which determines the behaviour of the
* web application used for the Client API. For full documentation of this
* resource, please see
* [REST API Reference: WebConfig](https://docs.stormpath.com/rest/product-guide/latest/reference.html?#web-config).
*
* This class should not be manually constructed. It should be obtained from one
* of these methods:
*
* - {@link Application#getWebConfig Application.getWebConfig()}.
*
* @param {Object} webConfigResource
*
* The JSON representation of this resource.
*/
function WebConfig() {
WebConfig.super_.apply(this, arguments);
}

utils.inherits(WebConfig, InstanceResource);

/**
* Retrieves the {@link Application} that this web configuration is attached to.
*
* @param {ExpansionOptions} options
* Options for retrieving the linked resources of the application.
*
* @param {Function} callback
* The function to call after the query has completed. It will be called with
* (err, {@link Application}).
*/
WebConfig.prototype.getApplication = function getWebConfigApplication(/* [options], callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.application.href, args.options, require('./Application'), args.callback);
};

/**
* Retrieves the {@link ApiKey} that this web config is using for signing tokens.
*
* @param {Options} options
* TODO when the official docs describe this
*
* @param {Function} callback
* The function to call after the query has completed. It will be called with
* (err, {@link ApiKey}).
*/
WebConfig.prototype.getSigningApiKey = function getSigningApiKey(/* [options], callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.signingApiKey.href, args.options, require('./ApiKey'), args.callback);
};

/**
* Retrieves the {@link Tenant} for this web configuration.
*
* @param {ExpansionOptions} options
* Options for retrieving the linked resources of the tenant.
*
* @param {Function} callback
* The function to call after the query has completed. It will be called with
* (err, {@link Tenant}).
*/
WebConfig.prototype.getTenant = function getWebConfigTenant(/* [options], callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.tenant.href, args.options, require('./Tenant'), args.callback);
Expand Down
35 changes: 35 additions & 0 deletions test/sp.resource.application_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var ApiKey = require('../lib/resource/ApiKey');
var DataStore = require('../lib/ds/DataStore');
var PasswordResetToken = require('../lib/resource/PasswordResetToken');
var AccountLinkingPolicy = require('../lib/resource/AccountLinkingPolicy');
var WebConfig = require('../lib/resource/WebConfig');
var nJwt = require('njwt');
var nJwtProperties = require('njwt/properties');
var uuid = require('uuid');
Expand Down Expand Up @@ -1501,5 +1502,39 @@ describe('Resources: ', function () {
});
});

describe('get web config', function () {
var sandbox, application, getResourceStub, cbSpy, app;
before(function () {
sandbox = sinon.sandbox.create();
app = {
webConfig: {
href: 'boom!'
}
};

application = new Application(app, dataStore);
getResourceStub = sandbox.stub(dataStore, 'getResource', function (href, options, ctor, cb) {
cb();
});
cbSpy = sandbox.spy();

application.getWebConfig(cbSpy);
});

after(function () {
sandbox.restore();
});

it('should get the web config', function () {
/* jshint -W030 */
getResourceStub.should.have.been.calledOnce;
cbSpy.should.have.been.calledOnce;
/* jshint +W030 */

getResourceStub.should.have.been
.calledWith(app.webConfig.href, null, WebConfig, cbSpy);
});
});

});
});

0 comments on commit 11cc87a

Please sign in to comment.