query_def.test.ts 3.0 KB

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