From 1664975dd124093489ff30370012b3cf30ad8dc7 Mon Sep 17 00:00:00 2001 From: Ivan Malagon Date: Wed, 13 Dec 2017 10:43:43 +0100 Subject: [PATCH] Add spec --- .../analysis/analyses-filters-params.js | 44 +++++++++++++++---- .../analysis/analysis-layers-dataviews.js | 3 +- test/acceptance/dataviews/overviews.js | 9 ++-- test/support/test-client.js | 5 ++- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/test/acceptance/analysis/analyses-filters-params.js b/test/acceptance/analysis/analyses-filters-params.js index 52861a3a..c4a17ae4 100644 --- a/test/acceptance/analysis/analyses-filters-params.js +++ b/test/acceptance/analysis/analyses-filters-params.js @@ -78,10 +78,11 @@ describe('analysis-filters-params', () => { it('should get a filtered histogram dataview with all filters', function(done) { const testClient = new TestClient(mapConfig, 1234); + const testParams = Object.assign({}, params, { + own_filter: 1 + }); - params.own_filter = 1; - - testClient.getDataview('pop_max_histogram', params, (err, dataview) => { + testClient.getDataview('pop_max_histogram', testParams, (err, dataview) => { assert.ok(!err, err); assert.equal(dataview.type, 'histogram'); @@ -93,10 +94,11 @@ describe('analysis-filters-params', () => { it('should get a filtered histogram dataview with all filters except my own filter', function(done) { const testClient = new TestClient(mapConfig, 1234); + const testParams = Object.assign({}, params, { + own_filter: 0 + }); - params.own_filter = 0; - - testClient.getDataview('pop_max_histogram', params, (err, dataview) => { + testClient.getDataview('pop_max_histogram', testParams, (err, dataview) => { assert.ok(!err, err); assert.equal(dataview.type, 'histogram'); @@ -108,10 +110,11 @@ describe('analysis-filters-params', () => { it('should get a filtered histogram dataview without filters', function(done) { const testClient = new TestClient(mapConfig, 1234); + const testParams = Object.assign({}, params, { + no_filters: 1 + }); - params.no_filters = 1; - - testClient.getDataview('pop_max_histogram', params, (err, dataview) => { + testClient.getDataview('pop_max_histogram', testParams, (err, dataview) => { assert.ok(!err, err); assert.equal(dataview.type, 'histogram'); @@ -121,4 +124,27 @@ describe('analysis-filters-params', () => { }); }); + it('should return an error if both no_filters and own_filter params are present', function (done) { + const testClient = new TestClient(mapConfig, 1234); + const expectedError = { + errors: ['Both own_filter and no_filters cannot be sent in the same request'], + errors_with_context: [{ + type: 'dataview', + message: 'Both own_filter and no_filters cannot be sent in the same request' + }] + }; + const testParams = Object.assign({}, params, { + no_filters: 1, + own_filter: 0, + response: { + status: 400 + } + }); + + testClient.getDataview('pop_max_histogram', testParams, (err, dataview) => { + assert.deepEqual(dataview, expectedError); + + testClient.drain(done); + }); + }); }); diff --git a/test/acceptance/analysis/analysis-layers-dataviews.js b/test/acceptance/analysis/analysis-layers-dataviews.js index a328ed09..8e95096a 100644 --- a/test/acceptance/analysis/analysis-layers-dataviews.js +++ b/test/acceptance/analysis/analysis-layers-dataviews.js @@ -109,7 +109,8 @@ describe('analysis-layers-dataviews', function() { min: 2e6 } } - } + }, + own_filter: 1 }; testClient.getDataview('pop_max_histogram', params, function(err, dataview) { diff --git a/test/acceptance/dataviews/overviews.js b/test/acceptance/dataviews/overviews.js index dcff687f..552b9ac6 100644 --- a/test/acceptance/dataviews/overviews.js +++ b/test/acceptance/dataviews/overviews.js @@ -393,7 +393,8 @@ describe('dataviews using tables with overviews', function() { var params = { filters: { dataviews: { test_histogram: { min: 2 } } - } + }, + own_filter: 1 }; var testClient = new TestClient(overviewsMapConfig); testClient.getDataview('test_histogram', params, function (err, histogram) { @@ -412,7 +413,8 @@ describe('dataviews using tables with overviews', function() { var params = { filters: { dataviews: { test_histogram: { max: -1 } } - } + }, + own_filter: 1 }; var testClient = new TestClient(overviewsMapConfig); testClient.getDataview('test_histogram', params, function (err, histogram) { @@ -433,7 +435,8 @@ describe('dataviews using tables with overviews', function() { var params = { filters: { dataviews: { test_histogram_date: { max: -1 } } - } + }, + own_filter: 1 }; var testClient = new TestClient(overviewsMapConfig); testClient.getDataview('test_histogram_date', params, function (err, histogram) { diff --git a/test/support/test-client.js b/test/support/test-client.js index c0525c64..be2560b0 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -414,8 +414,9 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) { var urlParams = {}; if (params.hasOwnProperty('no_filters')) { urlParams.no_filters = params.no_filters; - } else { - urlParams.own_filter = params.hasOwnProperty('own_filter') ? params.own_filter : 1; + } + if (params.hasOwnProperty('own_filter')) { + urlParams.own_filter = params.own_filter; } ['bbox', 'bins', 'start', 'end', 'aggregation', 'offset', 'categories'].forEach(function(extraParam) {