Skip to content

Commit

Permalink
Merge pull request #145 from screwdriver-cd/convertNumbers
Browse files Browse the repository at this point in the history
fix(399): convert string ids to numbers
  • Loading branch information
stjohnjohnson authored Dec 20, 2016
2 parents eeb0cfa + a51dd50 commit 9afa35e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/baseFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ class BaseFactory {
get(config) {
const params = {};

if (typeof config === 'number' || typeof config.id === 'number') {
params.id = config.id || config;
} else if (typeof config === 'object') {
if (typeof config === 'object' && !config.id) {
// Reduce to unique properties
this.model.keys.forEach((key) => {
params[key] = config[key];
});
} else {
const id = parseInt(config.id || config, 10);

if (id) {
params.id = id;
}
}

const lookup = {
Expand Down
10 changes: 10 additions & 0 deletions test/lib/baseFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ describe('Base Factory', () => {
})
);

it('converts string id to a number', () =>
factory.get('135323')
.then((model) => {
assert.instanceOf(model, Base);
assert.isTrue(datastore.get.calledOnce);
assert.deepEqual(model.datastore, datastore);
assert.deepEqual(model.scm, scm);
})
);

it('calls datastore get with config object and returns correct values', () =>
factory.get({ foo: 'foo', bar: 'bar' })
.then((model) => {
Expand Down

0 comments on commit 9afa35e

Please sign in to comment.