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

Commit f9ed091

Browse files
author
Timothy E. Johansson
committed
Merge pull request #339 from stormpath/feature-organization-support-on-directory
Feature: Add support for directory getOrganizations() and getOrganizationMappings()
2 parents 0186969 + 0ce2cc6 commit f9ed091

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

lib/resource/Directory.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ Directory.prototype.getProvider = function getProvider(/* [options,] callback */
7878
return this.dataStore.getResource(this.provider.href, options, require('./Provider'), callback);
7979
};
8080

81+
Directory.prototype.getOrganizations = function getOrganizations(/* [options,] callback */) {
82+
var args = Array.prototype.slice.call(arguments);
83+
84+
var callback = args.pop();
85+
var options = (args.length > 0) ? args.shift() : null;
86+
87+
return this.dataStore.getResource(this.organizations.href, options, require('./Organization'), callback);
88+
};
89+
90+
Directory.prototype.getOrganizationMappings = function getOrganizationMappings(/* [options,] callback */) {
91+
var args = Array.prototype.slice.call(arguments);
92+
93+
var callback = args.pop();
94+
var options = (args.length > 0) ? args.shift() : null;
95+
96+
return this.dataStore.getResource(this.organizationMappings.href, options, require('./OrganizationAccountStoreMapping'), callback);
97+
};
98+
8199
Directory.prototype.getCustomData = function getCustomData(/* [options,] callback */) {
82100
var args = Array.prototype.slice.call(arguments);
83101
var callback = args.pop();

test/sp.resource.directory_test.js

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var u = common.u;
77

88
var Account = require('../lib/resource/Account');
99
var Group = require('../lib/resource/Group');
10+
var Organization = require('../lib/resource/Organization');
11+
var OrganizationAccountStoreMapping = require('../lib/resource/OrganizationAccountStoreMapping');
1012
var Tenant = require('../lib/resource/Tenant');
1113
var Provider = require('../lib/resource/Provider');
1214
var Directory = require('../lib/resource/Directory');
@@ -285,7 +287,7 @@ describe('Resources: ', function () {
285287
dirObj = {provider: {href: providerObj.href}};
286288
app = new Directory(dirObj, dataStore);
287289

288-
nock(u.BASE_URL).get(u.v1(providerObj.href)).reply(200, providerObj);
290+
nock(u.BASE_URL).get(providerObj.href).reply(200, providerObj);
289291

290292
var args = [];
291293
if (data) {
@@ -326,7 +328,83 @@ describe('Resources: ', function () {
326328

327329
it('should call cb without options', function () {
328330
cbSpy.should.have.been.calledOnce;
329-
cbSpy.should.have.been.calledWith(undefined, undefined);
331+
cbSpy.should.have.been.calledWith();
332+
});
333+
});
334+
});
335+
336+
describe('get organizations', function () {
337+
describe('if organizations href are set', function () {
338+
var opt = {};
339+
340+
var getResourceStub;
341+
var sandbox = sinon.sandbox.create();
342+
var app = { organizationMappings: { href: 'boom!' } };
343+
var directory = new Directory(app, dataStore);
344+
var cbSpy = sandbox.spy();
345+
346+
before(function () {
347+
getResourceStub = sandbox.stub(dataStore, 'getResource', function (href, options, ctor, cb) {
348+
cb();
349+
});
350+
351+
directory.getOrganizations(cbSpy);
352+
directory.getOrganizations(opt, cbSpy);
353+
});
354+
355+
after(function () {
356+
sandbox.restore();
357+
});
358+
359+
it('should get organizations', function () {
360+
cbSpy.should.have.been.calledTwice;
361+
getResourceStub.should.have.been.calledTwice;
362+
363+
getResourceStub.should.have.been.calledWith(
364+
app.organizations.href, null, Organization, cbSpy
365+
);
366+
367+
getResourceStub.should.have.been.calledWith(
368+
app.organizations.href, opt, Organization, cbSpy
369+
);
370+
});
371+
});
372+
});
373+
374+
describe('get organization mappings', function () {
375+
describe('if organizationMappings href are set', function () {
376+
var opt = {};
377+
378+
var getResourceStub;
379+
var sandbox = sinon.sandbox.create();
380+
var app = { organizationMappings: { href: 'boom!' } };
381+
var directory = new Directory(app, dataStore);
382+
var cbSpy = sandbox.spy();
383+
384+
before(function () {
385+
getResourceStub = sandbox.stub(dataStore, 'getResource', function (href, options, ctor, cb) {
386+
cb();
387+
});
388+
389+
directory.getOrganizationMappings(cbSpy);
390+
directory.getOrganizationMappings(opt, cbSpy);
391+
});
392+
393+
after(function () {
394+
sandbox.restore();
395+
});
396+
397+
it('should get organization mappings', function () {
398+
cbSpy.should.have.been.calledTwice;
399+
getResourceStub.should.have.been.calledTwice;
400+
401+
getResourceStub.should.have.been.calledWith(
402+
app.organizationMappings.href, null, OrganizationAccountStoreMapping, cbSpy
403+
);
404+
405+
getResourceStub.should.have.been.calledWith(
406+
app.organizationMappings.href, opt, OrganizationAccountStoreMapping, cbSpy
407+
);
330408
});
331409
});
332410
});

0 commit comments

Comments
 (0)