Skip to content

Commit

Permalink
Bug fixes in getServiceConfig function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebianchi committed Nov 13, 2015
1 parent 081c163 commit 7f0e75f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ var webpack = require("webpack");
var build = function (minify, callback) {
webpack({
entry: "./src/asteroid-collections.js",
externals: {
"immutable": "umd immutable"
},
module: {
loaders: [{
test: /\.js$/,
Expand Down
12 changes: 6 additions & 6 deletions src/asteroid-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function init () {
}

export function getServiceConfig (providerName) {
const serviceConfiguration = this.collections.getIn([
SERVICE_CONFIG_COLLECTION,
providerName
]);
if (!serviceConfiguration) {
try {
return this.collections
.get(SERVICE_CONFIG_COLLECTION)
.find(serviceConfig => serviceConfig.get("service") === providerName)
.toJS();
} catch (ignore) {
throw new Error(`No configuration found for provider ${providerName}`);
}
return serviceConfiguration.toJS();
}
41 changes: 22 additions & 19 deletions test/unit/asteroid-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,33 @@ describe("`asteroid-collection` mixin", function () {
asteroidCollections.__ResetDependency__("SERVICE_CONFIG_COLLECTION");
});

it("should call the `getIn` function of collections with the correct parameter", function () {
it("should call the `get` function of collections with the correct parameter", function () {
const instance = {
collections: {
getIn: sinon.stub().returns(Immutable.Map())
get: sinon.stub().returns(Immutable.Map({id: Immutable.Map({service: "providerName"})}))
}
};
asteroidCollections.getServiceConfig.call(instance, providerName);
expect(instance.collections.getIn).to.have.callCount(1);
expect(instance.collections.getIn).to.have.been.calledWith([
SERVICE_CONFIG_COLLECTION,
providerName
]);
expect(instance.collections.get).to.have.callCount(1);
expect(instance.collections.get).to.have.been.calledWith(SERVICE_CONFIG_COLLECTION);
});

it("should return an object", function () {
const instance = {
collections: {
get: sinon.stub().returns(Immutable.Map({
id: Immutable.Map(
{service: "providerName", clientID: "clientID"}
)}
))
}
};
var ret = asteroidCollections.getServiceConfig.call(instance, providerName);
expect(ret).to.be.an.instanceOf(Object);
expect(ret).to.deep.equal({
service: "providerName",
clientID: "clientID"
});
});

it("should throw an `Error` with correct message if serviceConfiguration is `undefined`", function () {
Expand All @@ -123,21 +138,9 @@ describe("`asteroid-collection` mixin", function () {
const troubleMaker = () => {
asteroidCollections.getServiceConfig.call(instance, providerName);
};
// expect(ret).to.be.an.instanceOf(Error);
expect(troubleMaker).to.throw("No configuration found for provider providerName");
});

it("should return an object", function () {
const instance = {
collections: {
getIn: sinon.stub().returns(Immutable.Map())
}
};
var ret = asteroidCollections.getServiceConfig.call(instance, providerName);
expect(ret).to.be.an.instanceOf(Object);
expect(ret).to.deep.equal({});
});

});

});

0 comments on commit 7f0e75f

Please sign in to comment.