query_def_specs.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: [
  14. { type: 'count', field: '@value' },
  15. { type: 'sum', field: '@value' }
  16. ]
  17. };
  18. var response = queryDef.getPipelineAggOptions(targets);
  19. it('should return zero', function() {
  20. expect(response.length).to.be(2);
  21. });
  22. });
  23. describe('with count and moving average targets', function() {
  24. var targets = {
  25. metrics: [
  26. { type: 'count', field: '@value' },
  27. { type: 'moving_avg', field: '@value' }
  28. ]
  29. };
  30. var response = queryDef.getPipelineAggOptions(targets);
  31. it('should return one', function() {
  32. expect(response.length).to.be(1);
  33. });
  34. });
  35. describe('with derivatives targets', function() {
  36. var targets = {
  37. metrics: [
  38. { type: 'derivative', field: '@value' }
  39. ]
  40. };
  41. var response = queryDef.getPipelineAggOptions(targets);
  42. it('should return zero', function() {
  43. expect(response.length).to.be(0);
  44. });
  45. });
  46. });
  47. describe('isPipelineMetric', function() {
  48. describe('moving_avg', function() {
  49. var result = queryDef.isPipelineAgg('moving_avg');
  50. it('is pipe line metric', function() {
  51. expect(result).to.be(true);
  52. });
  53. });
  54. describe('count', function() {
  55. var result = queryDef.isPipelineAgg('count');
  56. it('is not pipe line metric', function() {
  57. expect(result).to.be(false);
  58. });
  59. });
  60. });
  61. describe('pipeline aggs depending on esverison', function() {
  62. describe('using esversion undefined', function() {
  63. it('should not get pipeline aggs', function() {
  64. expect(queryDef.getMetricAggTypes(undefined).length).to.be(9);
  65. });
  66. });
  67. describe('using esversion 1', function() {
  68. it('should not get pipeline aggs', function() {
  69. expect(queryDef.getMetricAggTypes(1).length).to.be(9);
  70. });
  71. });
  72. describe('using esversion 2', function() {
  73. it('should get pipeline aggs', function() {
  74. expect(queryDef.getMetricAggTypes(2).length).to.be(11);
  75. });
  76. });
  77. describe('using esversion 5', function() {
  78. it('should get pipeline aggs', function() {
  79. expect(queryDef.getMetricAggTypes(5).length).to.be(11);
  80. });
  81. });
  82. });
  83. });