Skip to content

Commit

Permalink
reorder and stub out tests to match #1
Browse files Browse the repository at this point in the history
  • Loading branch information
timwis committed Dec 2, 2015
1 parent b09c1cf commit 908c6ec
Showing 1 changed file with 76 additions and 54 deletions.
130 changes: 76 additions & 54 deletions test/soda-geoservices.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global describe, it */
require('should')
var convert = require('../index')
/* var inspect = function (data) {
console.log(require('util').inspect(data, false, 10, true))
} */
// var inspect = function (data) {
// console.log(require('util').inspect(data, false, 10, true))
// }

describe('select', function () {
it('multiple fields', function () {
Expand All @@ -20,8 +20,29 @@ describe('select', function () {
(it('operators', function () {
var query = convert('$select=foo * 3 AS bar')
})*/
})

describe('where', function () {
it('simple filters', function () {
var query = convert('foo=1&baz=quz')
query.should.have.property('where', "foo = 1 AND baz = 'quz'")
})

it('boolean operators', function () {
var query = convert('$where=foo > 1 and baz="quz"')
query.should.have.property('where', "foo > 1 AND baz = 'quz'")
})

// it('order of operations', function() {})
})

it('aggregation: sum', function () {
describe('group', function () {
it('group by', function () {
var query = convert('$group=foo')
query.should.have.property('groupByFieldsForStatistics', 'foo')
})

it('aggregation', function () {
// count, sum, avg, stddev, var, min, max
var query = convert('$select=foo, sum(bar)')
query.should.have.property('outStatistics', [{
Expand All @@ -31,7 +52,7 @@ describe('select', function () {
}])
})

it('aggregation: uppercase', function () {
it('aggregation with uppercase function name', function () {
// count, sum, avg, stddev, var, min, max
var query = convert('$select=foo, SUM(bar)')
query.should.have.property('outStatistics', [{
Expand All @@ -41,7 +62,7 @@ describe('select', function () {
}])
})

it('aggregation: count(*)', function () {
it('aggregation with wildcard', function () {
// count, sum, avg, stddev, var, min, max
var query = convert('$select=foo, count(*)')
query.should.have.property('outStatistics', [{
Expand All @@ -55,22 +76,28 @@ describe('select', function () {
var query = convert('$select=sum(foo) AS bar')
query.outStatistics[0].should.have.property('outStatisticFieldName', 'bar')
})
})

it('group by', function () {
var query = convert('$group=foo')
query.should.have.property('groupByFieldsForStatistics', 'foo')
describe('other', function () {
it('order with direction', function () {
var query = convert('$order=foo, bar desc')
query.should.have.property('orderByFields', 'foo, bar desc')
})

/* not sure how to query geoservices this way
it('date parts', function () {
var query = convert('$select=date_trunc_ym(date)')
})*/
it('limit', function () {
var query = convert('$limit=5000')
query.should.have.property('resultRecordCount', 5000)
})

/* pretty sure this is supported via UPPER()/LOWER()
it('lower/upper case', function () {
var query = convert('$select=lower(foo)')
})*/
it('offset', function () {
var query = convert('$offset=100')
query.should.have.property('resultOffset', 100)
})

// it('free-text search', function () {})
})

describe('select functions', function () {
it('extent', function () {
var query = convert('$select=extent(location)')
query.should.have.property('returnExtentOnly', true)
Expand All @@ -83,62 +110,57 @@ describe('select', function () {
query.should.have.property('returnCountOnly', true)
query.outFields.should.eql([])
})

// it('convex hull', function () {})

/* not sure how to query geoservices this way
it('date format', function () {
var query = convert('$select=date_trunc_ym(date)')
})*/

/* pretty sure this is supported via UPPER()/LOWER()
it('upper/lower case', function () {
var query = convert('$select=lower(foo)')
})*/

// it('case', function () {})
})

describe('filter', function () {
it('named filters', function () {
var query = convert('foo=1&baz=quz')
query.should.have.property('where', "foo = 1 AND baz = 'quz'")
describe('where functions', function () {
it('between', function () {
var query = convert('$where=salary between 40000 and 60000')
query.where.should.be.eql('salary BETWEEN 40000 AND 60000')
})

it('$where filters', function () {
var query = convert('$where=foo > 1 and baz="quz"')
query.should.have.property('where', "foo > 1 AND baz = 'quz'")
// it('not between', function () {})

// it('in', function() {})

// it('not in', function () {})

it('starts with', function () {
var query = convert("$where=starts_with(foo, 'bar')")
query.where.should.be.eql("foo LIKE 'bar%'")
})

// it('date format', function () {})

// https://dev.socrata.com/docs/functions/within_box.html
it('within_box', function () {
it('within box', function () {
var query = convert('$where=within_box(location, 46, -122, 47, -123)')
query.should.have.property('geometryType', 'esriGeometryEnvelope')
query.should.have.property('geometry', [-122, 46, -123, 47])
query.where.should.be.eql('1 = 1')
})

// https://dev.socrata.com/docs/functions/within_circle.html
it('within_circle', function () {
it('within circle', function () {
var query = convert('$where=within_circle(location, 47, -122, 500)')
query.should.have.property('geometry', [-122, 47])
query.should.have.property('distance', 500)
// query.should.have.property('units', 'meters') // not documented
query.where.should.be.eql('1 = 1')
})

it('between', function () {
var query = convert('$where=salary between 40000 and 60000')
query.where.should.be.eql('salary BETWEEN 40000 AND 60000')
})

it('starts with', function () {
var query = convert("$where=starts_with(foo, 'bar')")
query.where.should.be.eql("foo LIKE 'bar%'")
})
})

describe('sorting', function () {
it('order by', function () {
var query = convert('$order=foo, bar desc')
query.should.have.property('orderByFields', 'foo, bar desc')
})
})

describe('pagination', function () {
it('limit', function () {
var query = convert('$limit=5000')
query.should.have.property('resultRecordCount', 5000)
})

it('offset', function () {
var query = convert('$offset=100')
query.should.have.property('resultOffset', 100)
})
// it('within polygon', function () {})
})

0 comments on commit 908c6ec

Please sign in to comment.