Skip to content

Commit

Permalink
refactor: Rename test macro helper aggsExpectStrategy => nameTypeExpe…
Browse files Browse the repository at this point in the history
…ctStrategy
  • Loading branch information
sudo-suhas committed Jul 8, 2017
1 parent 9284df8 commit 65ac5f5
Show file tree
Hide file tree
Showing 32 changed files with 104 additions and 63 deletions.
2 changes: 1 addition & 1 deletion test/_macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function simpleExpect(keyName, propValue) {
* @param {Object} defaultDef
* @returns {function}
*/
export function aggsExpectStrategy(name, type, defaultDef) {
export function nameTypeExpectStrategy(name, type, defaultDef) {
return (keyName, propValue) => ({
[name]: {
[type]: Object.assign({ [keyName]: propValue }, defaultDef)
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/adjacency-matrix-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import test from 'ava';
import { AdjacencyMatrixAggregation, termQuery } from '../../src';
import { illegalCall, setsAggType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { illegalCall, setsAggType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = () => new AdjacencyMatrixAggregation('my_adj_mat_agg');

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_adj_mat_agg', 'adjacency_matrix')
nameTypeExpectStrategy('my_adj_mat_agg', 'adjacency_matrix')
);

const filterQryA = termQuery('user', 'kimchy');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/bucket-agg-base.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava';
import { Script } from '../../src';
import { BucketAggregationBase } from '../../src/aggregations/bucket-aggregations';
import { illegalParamType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { illegalParamType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = (...args) => new BucketAggregationBase('my_agg', 'my_type', ...args);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'my_type'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'my_type'));

test('can be instantiated', t => {
t.truthy(getInstance());
Expand Down
7 changes: 5 additions & 2 deletions test/aggregations-test/bucket-script-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import test from 'ava';
import { BucketScriptAggregation, Script } from '../../src';
import { setsAggType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = bucketsPath => new BucketScriptAggregation('my_agg', bucketsPath);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'bucket_script'));
const setsOption = makeSetsOptionMacro(
getInstance,
nameTypeExpectStrategy('my_agg', 'bucket_script')
);

test(setsAggType, BucketScriptAggregation, 'bucket_script');
test(setsOption, 'script', { param: 'params.my_var1 / params.my_var2' });
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/bucket-selector-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import test from 'ava';
import { BucketSelectorAggregation, Script } from '../../src';
import { setsAggType, illegalCall, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, illegalCall, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = bucketsPath => new BucketSelectorAggregation('my_agg', bucketsPath);

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_agg', 'bucket_selector')
nameTypeExpectStrategy('my_agg', 'bucket_selector')
);

test(setsAggType, BucketSelectorAggregation, 'bucket_selector');
Expand Down
7 changes: 5 additions & 2 deletions test/aggregations-test/cardinality-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import test from 'ava';
import { CardinalityAggregation } from '../../src';
import { setsAggType, illegalCall, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, illegalCall, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = field => new CardinalityAggregation('my_agg', field);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'cardinality'));
const setsOption = makeSetsOptionMacro(
getInstance,
nameTypeExpectStrategy('my_agg', 'cardinality')
);

test(setsAggType, CardinalityAggregation, 'cardinality');
test(illegalCall, CardinalityAggregation, 'format', 'my_agg');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/derivative-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava';
import { DerivativeAggregation } from '../../src';
import { setsAggType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = bucketsPath => new DerivativeAggregation('my_agg', bucketsPath);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'derivative'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'derivative'));

test(setsAggType, DerivativeAggregation, 'derivative');
test(setsOption, 'unit', { param: 'day' });
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/diversified-sampler-agg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { DiversifiedSamplerAggregation } from '../../src';
import {
setsAggType,
validatedCorrectly,
aggsExpectStrategy,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = () => new DiversifiedSamplerAggregation('my_samples', 'my_field');

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_samples', 'diversified_sampler', {
nameTypeExpectStrategy('my_samples', 'diversified_sampler', {
field: 'my_field'
})
);
Expand Down
7 changes: 5 additions & 2 deletions test/aggregations-test/extended-stats-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import test from 'ava';
import { ExtendedStatsAggregation } from '../../src';
import { setsAggType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = field => new ExtendedStatsAggregation('my_agg', field);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'extended_stats'));
const setsOption = makeSetsOptionMacro(
getInstance,
nameTypeExpectStrategy('my_agg', 'extended_stats')
);

test(setsAggType, ExtendedStatsAggregation, 'extended_stats');
test(setsOption, 'sigma', { param: 3 });
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/extended-stats-bucket-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import test from 'ava';
import { ExtendedStatsBucketAggregation } from '../../src';
import { setsAggType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = bucketsPath => new ExtendedStatsBucketAggregation('my_agg', bucketsPath);

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_agg', 'extended_stats_bucket')
nameTypeExpectStrategy('my_agg', 'extended_stats_bucket')
);

test(setsAggType, ExtendedStatsBucketAggregation, 'extended_stats_bucket');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/filters-agg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
illegalCall,
illegalParamType,
setsAggType,
aggsExpectStrategy,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = (...args) => new FiltersAggregation('my_filters_agg', ...args);

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_filters_agg', 'filters')
nameTypeExpectStrategy('my_filters_agg', 'filters')
);

const filterQryA = termQuery('user', 'kimchy');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/geo-bounds-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava';
import { GeoBoundsAggregation } from '../../src';
import { setsAggType, illegalCall, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, illegalCall, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = field => new GeoBoundsAggregation('my_agg', field);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'geo_bounds'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'geo_bounds'));

test(setsAggType, GeoBoundsAggregation, 'geo_bounds');
test(illegalCall, GeoBoundsAggregation, 'format', 'my_agg');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/geo-distance-agg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GeoDistanceAggregation, geoPoint } from '../../src';
import {
illegalCall,
illegalParamType,
aggsExpectStrategy,
nameTypeExpectStrategy,
makeSetsOptionMacro,
validatedCorrectly
} from '../_macros';
Expand All @@ -13,7 +13,7 @@ const getInstance = () => new GeoDistanceAggregation('my_geo_agg').range({ to: 1

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_geo_agg', 'geo_distance', {
nameTypeExpectStrategy('my_geo_agg', 'geo_distance', {
ranges: [{ to: 100 }]
})
);
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/geo-hash-grid-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import test from 'ava';
import { GeoHashGridAggregation } from '../../src';
import { illegalCall, setsAggType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { illegalCall, setsAggType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = () => new GeoHashGridAggregation('my_geo_agg');

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_geo_agg', 'geohash_grid')
nameTypeExpectStrategy('my_geo_agg', 'geohash_grid')
);

test(setsAggType, GeoHashGridAggregation, 'geohash_grid');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/histogram-agg-base.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava';
import { HistogramAggregationBase } from '../../src/aggregations/bucket-aggregations';
import { aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = (...args) => new HistogramAggregationBase('my_agg', 'my_type', ...args);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'my_type'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'my_type'));

test(setsOption, 'interval', { param: 'year' });
test(setsOption, 'format', { param: '####.00' });
Expand Down
12 changes: 10 additions & 2 deletions test/aggregations-test/matrix-stats-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import test from 'ava';
import { MatrixStatsAggregation } from '../../src';
import { setsAggType, illegalParamType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import {
setsAggType,
illegalParamType,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = fields => new MatrixStatsAggregation('my_agg', fields);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'matrix_stats'));
const setsOption = makeSetsOptionMacro(
getInstance,
nameTypeExpectStrategy('my_agg', 'matrix_stats')
);

test(setsAggType, MatrixStatsAggregation, 'matrix_stats');
test(illegalParamType, getInstance(), 'fields', 'Array');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/metrics-agg-base.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava';
import { Script } from '../../src';
import { MetricsAggregationBase } from '../../src/aggregations/metrics-aggregations';
import { illegalParamType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { illegalParamType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = field => new MetricsAggregationBase('my_agg', 'my_type', field);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'my_type'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'my_type'));

test('can be instantiated', t => {
t.truthy(getInstance());
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/moving-average-agg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
setsAggType,
illegalCall,
validatedCorrectly,
aggsExpectStrategy,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = bucketsPath => new MovingAverageAggregation('my_agg', bucketsPath);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'moving_avg'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'moving_avg'));

test(setsAggType, MovingAverageAggregation, 'moving_avg');
test(illegalCall, MovingAverageAggregation, 'format', 'my_agg');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/nested-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import test from 'ava';
import { NestedAggregation } from '../../src';
import { setsAggType, illegalCall, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, illegalCall, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = (...args) => new NestedAggregation('my_agg', ...args);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'nested'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'nested'));

test(setsAggType, NestedAggregation, 'nested');
test(illegalCall, NestedAggregation, 'field', 'my_agg');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/percentile-ranks-agg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {
setsAggType,
illegalCall,
illegalParamType,
aggsExpectStrategy,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = (field, values) => new PercentileRanksAggregation('my_agg', field, values);

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_agg', 'percentile_ranks')
nameTypeExpectStrategy('my_agg', 'percentile_ranks')
);

test(setsAggType, PercentileRanksAggregation, 'percentile_ranks');
Expand Down
12 changes: 10 additions & 2 deletions test/aggregations-test/percentiles-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import test from 'ava';
import { PercentilesAggregation } from '../../src';
import { setsAggType, illegalParamType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import {
setsAggType,
illegalParamType,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = field => new PercentilesAggregation('my_agg', field);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'percentiles'));
const setsOption = makeSetsOptionMacro(
getInstance,
nameTypeExpectStrategy('my_agg', 'percentiles')
);

test(setsAggType, PercentilesAggregation, 'percentiles');
test(illegalParamType, getInstance(), 'percents', 'Array');
Expand Down
9 changes: 7 additions & 2 deletions test/aggregations-test/percentiles-bucket-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import test from 'ava';
import { PercentilesBucketAggregation } from '../../src';
import { setsAggType, illegalParamType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import {
setsAggType,
illegalParamType,
nameTypeExpectStrategy,
makeSetsOptionMacro
} from '../_macros';

const getInstance = bucketsPath => new PercentilesBucketAggregation('my_agg', bucketsPath);

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_agg', 'percentiles_bucket')
nameTypeExpectStrategy('my_agg', 'percentiles_bucket')
);

test(setsAggType, PercentilesBucketAggregation, 'percentiles_bucket');
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/pipeline-agg-base.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import test from 'ava';
import { PipelineAggregationBase } from '../../src/aggregations/pipeline-aggregations';
import { validatedCorrectly, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { validatedCorrectly, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = bucketsPath =>
new PipelineAggregationBase('my_agg', 'my_type', '', bucketsPath);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'my_type'));
const setsOption = makeSetsOptionMacro(getInstance, nameTypeExpectStrategy('my_agg', 'my_type'));

test(validatedCorrectly, getInstance, 'gapPolicy', ['skip', 'insert_zeros']);
test(setsOption, 'bucketsPath', { param: 'my_buckets_path' });
Expand Down
4 changes: 2 additions & 2 deletions test/aggregations-test/range-agg-base.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import test from 'ava';
import { RangeAggregationBase } from '../../src/aggregations/bucket-aggregations';
import { illegalParamType, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { illegalParamType, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = (...args) =>
new RangeAggregationBase('my_agg', 'my_type', ...args).range({ from: 10, to: 20 });

const setsOption = makeSetsOptionMacro(
getInstance,
aggsExpectStrategy('my_agg', 'my_type', {
nameTypeExpectStrategy('my_agg', 'my_type', {
ranges: [{ from: 10, to: 20 }]
})
);
Expand Down
7 changes: 5 additions & 2 deletions test/aggregations-test/reverse-nested-agg.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import test from 'ava';
import { ReverseNestedAggregation } from '../../src';
import { setsAggType, illegalCall, aggsExpectStrategy, makeSetsOptionMacro } from '../_macros';
import { setsAggType, illegalCall, nameTypeExpectStrategy, makeSetsOptionMacro } from '../_macros';

const getInstance = (...args) => new ReverseNestedAggregation('my_agg', ...args);

const setsOption = makeSetsOptionMacro(getInstance, aggsExpectStrategy('my_agg', 'reverse_nested'));
const setsOption = makeSetsOptionMacro(
getInstance,
nameTypeExpectStrategy('my_agg', 'reverse_nested')
);

test(setsAggType, ReverseNestedAggregation, 'reverse_nested');
test(illegalCall, ReverseNestedAggregation, 'field', 'my_agg');
Expand Down
Loading

0 comments on commit 65ac5f5

Please sign in to comment.