Commit 0b285845 by carl bergquist

adds spec for query builder

parent d3ff4bf7
......@@ -37,7 +37,7 @@ function (angular, _, queryDef) {
$scope.settingsLinkText = '';
$scope.aggDef = _.findWhere($scope.metricAggTypes, {value: $scope.agg.type});
if (!$scope.agg.field && $scope.agg.type !== 'moving_avg') {
if (!$scope.agg.field) {
$scope.agg.field = 'select field';
}
......
......@@ -171,7 +171,11 @@ function () {
var metricAgg = null;
if (metric.type === 'moving_avg') {
metricAgg = {buckets_path: "1"};
if (metric.mavgSource && /^\d*$/.test(metric.mavgSource)) {
metricAgg = { buckets_path: metric.mavgSource };
} else {
continue;
}
} else {
metricAgg = {field: metric.field};
}
......
......@@ -159,10 +159,15 @@ describe('ElasticQueryBuilder', function() {
var query = builder.build({
metrics: [
{
id: '3',
type: 'sum',
field: '@value'
},
{
id: '2',
type: 'moving_avg',
field: '@value',
aggregation: 'sum'
field: '3',
mavgSource: '3'
}
],
bucketAggs: [
......@@ -171,9 +176,43 @@ describe('ElasticQueryBuilder', function() {
});
var firstLevel = query.aggs["3"];
console.log(JSON.stringify(query));
expect(firstLevel.aggs["2"]).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("99");
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("3");
});
it('with broken moving average', function() {
var query = builder.build({
metrics: [
{
id: '3',
type: 'sum',
field: '@value'
},
{
id: '2',
type: 'moving_avg',
field: '3',
mavgSource: '3'
},
{
id: '4',
type: 'moving_avg',
field: '3',
mavgSource: 'Metric to apply moving average'
}
],
bucketAggs: [
{ type: 'date_histogram', field: '@timestamp', id: '3' }
],
});
var firstLevel = query.aggs["3"];
expect(firstLevel.aggs["2"]).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("3");
expect(firstLevel.aggs["4"]).to.be(undefined);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment