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

Commit 11cc87a

Browse files
author
Luka Skukan
committed
Add docs and update tests to reflect everything correctly
1 parent b441dab commit 11cc87a

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

lib/resource/Application.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,9 +1487,17 @@ Application.prototype.getAccountLinkingPolicy = function getApplicationAccountLi
14871487
return this.dataStore.getResource(this.accountLinkingPolicy.href, args.options, require('./AccountLinkingPolicy'), args.callback);
14881488
};
14891489

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

14951503
module.exports = Application;

lib/resource/WebConfig.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,73 @@
33
var InstanceResource = require('./InstanceResource');
44
var utils = require('../utils');
55

6+
/**
7+
* @class WebConfig
8+
*
9+
* @augments {InstanceResource}
10+
*
11+
* @description
12+
*
13+
* Encapsulates an WebConfig resource, which determines the behaviour of the
14+
* web application used for the Client API. For full documentation of this
15+
* resource, please see
16+
* [REST API Reference: WebConfig](https://docs.stormpath.com/rest/product-guide/latest/reference.html?#web-config).
17+
*
18+
* This class should not be manually constructed. It should be obtained from one
19+
* of these methods:
20+
*
21+
* - {@link Application#getWebConfig Application.getWebConfig()}.
22+
*
23+
* @param {Object} webConfigResource
24+
*
25+
* The JSON representation of this resource.
26+
*/
627
function WebConfig() {
728
WebConfig.super_.apply(this, arguments);
829
}
930

1031
utils.inherits(WebConfig, InstanceResource);
1132

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

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

63+
/**
64+
* Retrieves the {@link Tenant} for this web configuration.
65+
*
66+
* @param {ExpansionOptions} options
67+
* Options for retrieving the linked resources of the tenant.
68+
*
69+
* @param {Function} callback
70+
* The function to call after the query has completed. It will be called with
71+
* (err, {@link Tenant}).
72+
*/
2273
WebConfig.prototype.getTenant = function getWebConfigTenant(/* [options], callback */) {
2374
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
2475
return this.dataStore.getResource(this.tenant.href, args.options, require('./Tenant'), args.callback);

test/sp.resource.application_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var ApiKey = require('../lib/resource/ApiKey');
1919
var DataStore = require('../lib/ds/DataStore');
2020
var PasswordResetToken = require('../lib/resource/PasswordResetToken');
2121
var AccountLinkingPolicy = require('../lib/resource/AccountLinkingPolicy');
22+
var WebConfig = require('../lib/resource/WebConfig');
2223
var nJwt = require('njwt');
2324
var nJwtProperties = require('njwt/properties');
2425
var uuid = require('uuid');
@@ -1501,5 +1502,39 @@ describe('Resources: ', function () {
15011502
});
15021503
});
15031504

1505+
describe('get web config', function () {
1506+
var sandbox, application, getResourceStub, cbSpy, app;
1507+
before(function () {
1508+
sandbox = sinon.sandbox.create();
1509+
app = {
1510+
webConfig: {
1511+
href: 'boom!'
1512+
}
1513+
};
1514+
1515+
application = new Application(app, dataStore);
1516+
getResourceStub = sandbox.stub(dataStore, 'getResource', function (href, options, ctor, cb) {
1517+
cb();
1518+
});
1519+
cbSpy = sandbox.spy();
1520+
1521+
application.getWebConfig(cbSpy);
1522+
});
1523+
1524+
after(function () {
1525+
sandbox.restore();
1526+
});
1527+
1528+
it('should get the web config', function () {
1529+
/* jshint -W030 */
1530+
getResourceStub.should.have.been.calledOnce;
1531+
cbSpy.should.have.been.calledOnce;
1532+
/* jshint +W030 */
1533+
1534+
getResourceStub.should.have.been
1535+
.calledWith(app.webConfig.href, null, WebConfig, cbSpy);
1536+
});
1537+
});
1538+
15041539
});
15051540
});

0 commit comments

Comments
 (0)