query_def_specs.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { describe, it, expect } from 'test/lib/common';
  2. import * as queryDef from '../query_def';
  3. describe('ElasticQueryDef', function() {
  4. describe('getPipelineAggOptions', function() {
  5. describe('with zero targets', function() {
  6. var response = queryDef.getPipelineAggOptions([]);
  7. it('should return zero', function() {
  8. expect(response.length).to.be(0);
  9. });
  10. });
  11. describe('with count and sum targets', function() {
  12. var targets = {
  13. metrics: [{ type: 'count', field: '@value' }, { type: 'sum', field: '@value' }],
  14. };
  15. var response = queryDef.getPipelineAggOptions(targets);
  16. it('should return zero', function() {
  17. expect(response.length).to.be(2);
  18. });
  19. });
  20. describe('with count and moving average targets', function() {
  21. var targets = {
  22. metrics: [{ type: 'count', field: '@value' }, { type: 'moving_avg', field: '@value' }],
  23. };
  24. var response = queryDef.getPipelineAggOptions(targets);
  25. it('should return one', function() {
  26. expect(response.length).to.be(1);
  27. });
  28. });
  29. describe('with derivatives targets', function() {
  30. var targets = {
  31. metrics: [{ type: 'derivative', field: '@value' }],
  32. };
  33. var response = queryDef.getPipelineAggOptions(targets);
  34. it('should return zero', function() {
  35. expect(response.length).to.be(0);
  36. });
  37. });
  38. });
  39. describe('isPipelineMetric', function() {
  40. describe('moving_avg', function() {
  41. var result = queryDef.isPipelineAgg('moving_avg');
  42. it('is pipe line metric', function() {
  43. expect(result).to.be(true);
  44. });
  45. });
  46. describe('count', function() {
  47. var result = queryDef.isPipelineAgg('count');
  48. it('is not pipe line metric', function() {
  49. expect(result).to.be(false);
  50. });
  51. });
  52. });
  53. describe('pipeline aggs depending on esverison', function() {
  54. describe('using esversion undefined', function() {
  55. it('should not get pipeline aggs', function() {
  56. expect(queryDef.getMetricAggTypes(undefined).length).to.be(9);
  57. });
  58. });
  59. describe('using esversion 1', function() {
  60. it('should not get pipeline aggs', function() {
  61. expect(queryDef.getMetricAggTypes(1).length).to.be(9);
  62. });
  63. });
  64. describe('using esversion 2', function() {
  65. it('should get pipeline aggs', function() {
  66. expect(queryDef.getMetricAggTypes(2).length).to.be(11);
  67. });
  68. });
  69. describe('using esversion 5', function() {
  70. it('should get pipeline aggs', function() {
  71. expect(queryDef.getMetricAggTypes(5).length).to.be(11);
  72. });
  73. });
  74. });
  75. });