Skip to content

Commit

Permalink
fix: Merge pull request #261 from pelias/allow-string-and-integer-for…
Browse files Browse the repository at this point in the history
…-importplace

allow string or integer for importPlace value
  • Loading branch information
trescube authored Jul 31, 2017
2 parents 3d25120 + 0bf0efa commit 5abe6e6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The following configuration options are supported by this importer.
| `imports.whosonfirst.api_key` | no | | used by the filtered download script, must be set if using `imports.whosonfirst.importPlace` config option. Visit the [Mapzen Developers dashboard](https://mapzen.com/developers) to get a working api key |
| `imports.whosonfirst.importPostalcodes` | no | false | set to `true` to include postalcodes in the data download and import process |
| `imports.whosonfirst.importVenues` | no | false | set to `true` to include venues in the data download and import process |
| `imports.whosonfirst.importPlace` | no | | set to a WOF id string indicating the region of interest, only data pertaining to that place shall be downloaded. Use the WOF [spelunker tool](https://whosonfirst.mapzen.com/spelunker/) search for an ID of a place. |
| `imports.whosonfirst.importPlace` | no | | set to a WOF id (number or string) indicating the region of interest, only data pertaining to that place shall be downloaded. Use the WOF [spelunker tool](https://whosonfirst.mapzen.com/spelunker/) search for an ID of a place. |
| `imports.whosonfirst.missingFilesAreFatal` | no | false | set to `true` for missing files from [Who's on First bundles](https://whosonfirst.mapzen.com/bundles/) to stop the import process |

## Downloading the Data
Expand All @@ -78,7 +78,7 @@ that are parents or descendants of the specified place. See the configuration de
We currently only support a single ID at a time. If multiple places need to be downloaded, the script can be executed multiple times;
one for each desired place.

**Warning**: It is recommended to only use the download filtering option for places more granular than `country`.
**Warning**: It is recommended to only use the download filtering option for places more granular than `country`.
The filtering script is intended for small areas and so has not been tested fully for large ones.

**Warning**: Who's on First data is _big_. Just the hierarchy data is tens of GB, and the full dataset is over 100GB on disk.
Expand Down
2 changes: 1 addition & 1 deletion schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = Joi.object().keys({
imports: Joi.object().keys({
whosonfirst: Joi.object().keys({
datapath: Joi.string(),
importPlace: Joi.string(),
importPlace: Joi.number().integer(),
api_key: Joi.string(),
importVenues: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
importPostalcodes: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true),
Expand Down
77 changes: 77 additions & 0 deletions test/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,80 @@ tape('tests for looking up hierarchies', function(test) {
});

});

tape('battery of importPlace tests', test => {
test.test('string importPlace should be cast as number', t => {
const config = {
imports: {
whosonfirst: {
datapath: '/path/to/data',
importPlace: '123'
}
}
};

const validated = Joi.validate(config, schema);

t.equals(validated.value.imports.whosonfirst.importPlace, 123);
t.end();

});

test.test('non-string importPlace should remain as number', t => {
const config = {
imports: {
whosonfirst: {
datapath: '/path/to/data',
importPlace: 123
}
}
};

const validated = Joi.validate(config, schema);

t.equals(validated.value.imports.whosonfirst.importPlace, 123);
t.end();

});

test.test('non-string/integer importPlace values should not validate', t => {
[null, false, {}, [], 'string'].forEach((value) => {
const config = {
imports: {
whosonfirst: {
datapath: '/path/to/data',
importPlace: value
}
}
};

const result = Joi.validate(config, schema);

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"importPlace" must be a number');

});

t.end();

});

test.test('non-integer importPlace values should not validate', t => {
const config = {
imports: {
whosonfirst: {
datapath: '/path/to/data',
importPlace: 17.3
}
}
};

const result = Joi.validate(config, schema);

t.equals(result.error.details.length, 1);
t.equals(result.error.details[0].message, '"importPlace" must be an integer');
t.end();

});

});

0 comments on commit 5abe6e6

Please sign in to comment.