From 64b664e1f389fc3c81e85b90788db061db0bed37 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 4 Sep 2017 17:14:53 +1200 Subject: [PATCH] add missing params --- src/endpoints/v1/events.js | 4 +- src/endpoints/v1/schemas/events.json | 57 +++++++++++++++++++++++++++- src/endpoints/v1/schemas/places.json | 4 ++ test/test_events_search.js | 25 ++++++++++++ test/test_events_validation.js | 23 +++++++++++ test/test_places.js | 17 +++++++++ test/test_places_validation.js | 28 ++++++++++++++ 7 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 test/test_places_validation.js diff --git a/src/endpoints/v1/events.js b/src/endpoints/v1/events.js index bc054b9..4498081 100644 --- a/src/endpoints/v1/events.js +++ b/src/endpoints/v1/events.js @@ -22,8 +22,8 @@ class Events extends BaseEndpoint { super(client) this.schema = EventSchema - this.arrayOptions = ['category', 'sort', 'top_events.sort', 'rank_level', 'label', 'country','place.scope','place.exact'] - this.integerOptions = ['limit', 'offset', 'rank_level'] + this.arrayOptions = ['category', 'sort', 'top_events.sort', 'rank_level', 'label', 'country','place.scope','place.exact', 'state'] + this.integerOptions = ['limit', 'offset', 'rank_level', 'signal.significance'] this.accountId = accountId diff --git a/src/endpoints/v1/schemas/events.json b/src/endpoints/v1/schemas/events.json index 5e08780..07a844f 100644 --- a/src/endpoints/v1/schemas/events.json +++ b/src/endpoints/v1/schemas/events.json @@ -32,6 +32,42 @@ "country": { "type": "array" }, + "state": { + "items": { + "enum": [ + "active", + "deleted" + ] + }, + "type": "array" + }, + "signal.id": { + "type": "string" + }, + "signal.analysis_from": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, + "signal.analysis_to": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, + "signal.analysis_tz": { + "type": "string" + }, + "signal.significance": { + "type": "integer", + "minimum": 0, + "maximum": 100 + }, + "signal.metric": { + "type": "string", + "pattern": "^(demand|lead|span)$" + }, + "signal.explain": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, "start.tz": { "type": "string" }, @@ -70,7 +106,26 @@ "type": "string", "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" }, - "active.tz": { + "updated.tz": { + "type": "string" + }, + "updated.gt": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, + "updated.gte": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, + "updated.lt": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, + "updated.lte": { + "type": "string", + "pattern": "^([0-9]{4})-[0-9]{2}-[0-9]{2}$" + }, + "active.tz": { "type": "string" }, "active.gt": { diff --git a/src/endpoints/v1/schemas/places.json b/src/endpoints/v1/schemas/places.json index d02eb1a..31b77f3 100644 --- a/src/endpoints/v1/schemas/places.json +++ b/src/endpoints/v1/schemas/places.json @@ -18,6 +18,10 @@ "minimum": 1, "maximum": 200 }, + "location": { + "type": "string", + "pattern": "@([\\-\\+]?\\d+(\\.\\d+)?),([\\-\\+]?\\d+(\\.\\d+)?)" + }, "type": { "items": { "enum": [ diff --git a/test/test_events_search.js b/test/test_events_search.js index 7482269..0360201 100644 --- a/test/test_events_search.js +++ b/test/test_events_search.js @@ -117,6 +117,31 @@ describe('Events', () => { }), + it('Search - Delta (updated and state filter)', (done) => { + + let c = new Client({access_token: test_client_credentials_access_token}) + + c.events.search({ + 'updated.gte': '2017-05-01', + 'updated.lte': '2017-05-02', + 'label': ['performing-arts'], + 'country': 'US', + 'sort': ['start'], + 'state': ['deleted'] + }) + .then((results)=> { + + // Expect some results + expect(results.toArray().length).toEqual(10) + + expect(results.toArray()[0]['id']).toEqual('O8aaM8kalk56') + + done() + + }).catch(done) + + }), + it('Search - count only', (done) => { let c = new Client({access_token: test_client_credentials_access_token}) diff --git a/test/test_events_validation.js b/test/test_events_validation.js index d1ec8b0..508c17a 100644 --- a/test/test_events_validation.js +++ b/test/test_events_validation.js @@ -50,6 +50,17 @@ describe('Event.Validation', () => { expect(validate({category: 'blah'}).valid).toNotExist() }) + it('State - Valid', () => { + expect(validate({state: 'deleted'}).valid).toExist() + expect(validate({state: 'active,deleted'}).valid).toExist() + expect(validate({state: ['active','deleted']}).valid).toExist() + }) + + it('State - Invalid', () => { + expect(validate({state: 'blah'}).valid).toNotExist() + expect(validate({state: ['blah']}).valid).toNotExist() + }) + it('Limit - Valid', () => { expect(validate({limit: 100}).valid).toExist() expect(validate({limit: '100'}).valid).toExist() @@ -88,6 +99,18 @@ describe('Event.Validation', () => { expect(validate({'start.gt': '2016'}).valid).toNotExist() }) + it('Updated - Valid', () => { + expect(validate({'updated.tz': 'America/New_York'}).valid).toExist() + expect(validate({'updated.gt': '2016-01-01'}).valid).toExist() + expect(validate({'updated.gte': '2016-01-01'}).valid).toExist() + expect(validate({'updated.lt': '2016-01-01'}).valid).toExist() + expect(validate({'updated.lte': '2016-01-01'}).valid).toExist() + }) + + it('Updated - Invalid', () => { + expect(validate({'updated.gt': '2016'}).valid).toNotExist() + }) + it('End - Valid', () => { expect(validate({'end.tz': 'America/New_York'}).valid).toExist() expect(validate({'end.gt': '2016-01-01'}).valid).toExist() diff --git a/test/test_places.js b/test/test_places.js index 33b14e1..8ee25af 100644 --- a/test/test_places.js +++ b/test/test_places.js @@ -65,4 +65,21 @@ describe('Places', () => { }) + it('Search by Location', (done) => { + + let c = new Client({ access_token : test_user_password_access_token}) + + c.places.search({location : '@40.66677,-73.88236'}) + .then((results)=>{ + + expect(results.toArray().length).toEqual(10) + + expect(results.toArray()[0].country).toEqual("United States") + + done() + + }).catch(done) + + }) + }) diff --git a/test/test_places_validation.js b/test/test_places_validation.js new file mode 100644 index 0000000..bc2c103 --- /dev/null +++ b/test/test_places_validation.js @@ -0,0 +1,28 @@ +/* + Event Validation Tests + +*/ + +import _ from "lodash" +_.extend(global, require('./shared')) + +import Client from '../src/client' + +let c = new Client() + +function validate(options){ + return c.places.validate(options) +} + +describe('Place.Validation', () => { + + it('ID - Valid', () => { + expect(validate({id: '123'}).valid).toExist() + }) + + it('Location - Valid', () => { + expect(validate({location: '@40.66677,-73.88236'}).valid).toExist() + }) + + +})