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

Commit

Permalink
add test for client.getApiKeyById
Browse files Browse the repository at this point in the history
required some fixes for env hacks that are done earlier in this script
  • Loading branch information
Robert committed Jan 24, 2017
1 parent ef1eb32 commit 9ada1a7
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions test/sp.client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var expect = common.expect;

var Account = require('../lib/resource/Account');
var Application = require('../lib/resource/Application');
var ApiKey = require('../lib/resource/ApiKey');
var Challenge = require('../lib/resource/Challenge');
var Client = require('../lib/Client');
var DataStore = require('../lib/ds/DataStore');
Expand Down Expand Up @@ -79,7 +80,11 @@ describe('Client', function () {
client.on('ready', function () {
expect(client._dataStore.requestExecutor.baseUrl).to.equal('https://api.stormpath.com/v1');
// restore environment value
process.env.STORMPATH_CLIENT_BASEURL = oldValue;
if (oldValue) {
process.env.STORMPATH_CLIENT_BASEURL = oldValue;
} else {
delete process.env.STORMPATH_CLIENT_BASEURL;
}
done();
});

Expand All @@ -99,14 +104,19 @@ describe('Client', function () {
client.on('ready', function () {
expect(client._dataStore.requestExecutor.baseUrl).to.equal(url);
// restore environment value
process.env.STORMPATH_CLIENT_BASEURL = oldValue;
if (oldValue) {
process.env.STORMPATH_CLIENT_BASEURL = oldValue;
} else {
delete process.env.STORMPATH_CLIENT_BASEURL;
}
done();
});
});

it('should allow me to change the base url through the environment',function(done){
// temporarily set a new environment provided url, save the old one if it exists
var oldValue = process.env.STORMPATH_CLIENT_BASEURL;

process.env.STORMPATH_CLIENT_BASEURL = 'https://foo/v1';

var client = makeTestClient({apiKey: apiKey });
Expand All @@ -118,7 +128,11 @@ describe('Client', function () {
client.on('ready', function () {
expect(client._dataStore.requestExecutor.baseUrl).to.equal('https://foo/v1');
// restore environment value
process.env.STORMPATH_CLIENT_BASEURL = oldValue;
if (oldValue) {
process.env.STORMPATH_CLIENT_BASEURL = oldValue;
} else {
delete process.env.STORMPATH_CLIENT_BASEURL;
}
done();
});
});
Expand Down Expand Up @@ -1027,6 +1041,41 @@ describe('Client', function () {
});
});

describe('call to get ApiKeyById', function () {
var sandbox, client, getResourceStub, cbSpy, href;

before(function (done) {
sandbox = sinon.sandbox.create();
cbSpy = sandbox.spy();
href = 'https://api.stormpath.com/v1/apiKeys/foo';

client = makeTestClient();

client.on('error', function (err) {
throw err;
});

client.on('ready', function () {
getResourceStub = sandbox.stub(client._dataStore, 'getResource', function (href, options, ctor, cb) {
cb();
});

client.getApiKeyById('foo', null, cbSpy);

done();
});
});

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

it('should get account', function () {
getResourceStub.should.have.been
.calledWith(href, null, ApiKey, cbSpy);
});
});

describe('call to get application', function () {
var sandbox, client, getResourceStub, cbSpy, href, opt;
before(function (done) {
Expand Down

0 comments on commit 9ada1a7

Please sign in to comment.