From 0bf0efa0774464de5fb7ed094176a07ed0157852 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Mon, 31 Jul 2017 14:36:02 -0400 Subject: [PATCH] allow string or integer for importPlace value --- README.md | 4 +-- schema.js | 2 +- test/schema.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8e042534..f703ef96 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/schema.js b/schema.js index 63121af0..93cb365f 100644 --- a/schema.js +++ b/schema.js @@ -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), diff --git a/test/schema.js b/test/schema.js index e910024d..3cd55d3f 100644 --- a/test/schema.js +++ b/test/schema.js @@ -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(); + + }); + +});