query_def.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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('pipeline aggs depending on esverison', () => {
  53. describe('using esversion undefined', () => {
  54. test('should not get pipeline aggs', () => {
  55. expect(queryDef.getMetricAggTypes(undefined).length).toBe(9);
  56. });
  57. });
  58. describe('using esversion 1', () => {
  59. test('should not get pipeline aggs', () => {
  60. expect(queryDef.getMetricAggTypes(1).length).toBe(9);
  61. });
  62. });
  63. describe('using esversion 2', () => {
  64. test('should get pipeline aggs', () => {
  65. expect(queryDef.getMetricAggTypes(2).length).toBe(11);
  66. });
  67. });
  68. describe('using esversion 5', () => {
  69. test('should get pipeline aggs', () => {
  70. expect(queryDef.getMetricAggTypes(5).length).toBe(11);
  71. });
  72. });
  73. });
  74. });