query_def_specs.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: [{ type: "derivative", field: "@value" }]
  38. };
  39. var response = queryDef.getPipelineAggOptions(targets);
  40. it("should return zero", function() {
  41. expect(response.length).to.be(0);
  42. });
  43. });
  44. });
  45. describe("isPipelineMetric", function() {
  46. describe("moving_avg", function() {
  47. var result = queryDef.isPipelineAgg("moving_avg");
  48. it("is pipe line metric", function() {
  49. expect(result).to.be(true);
  50. });
  51. });
  52. describe("count", function() {
  53. var result = queryDef.isPipelineAgg("count");
  54. it("is not pipe line metric", function() {
  55. expect(result).to.be(false);
  56. });
  57. });
  58. });
  59. describe("pipeline aggs depending on esverison", function() {
  60. describe("using esversion undefined", function() {
  61. it("should not get pipeline aggs", function() {
  62. expect(queryDef.getMetricAggTypes(undefined).length).to.be(9);
  63. });
  64. });
  65. describe("using esversion 1", function() {
  66. it("should not get pipeline aggs", function() {
  67. expect(queryDef.getMetricAggTypes(1).length).to.be(9);
  68. });
  69. });
  70. describe("using esversion 2", function() {
  71. it("should get pipeline aggs", function() {
  72. expect(queryDef.getMetricAggTypes(2).length).to.be(11);
  73. });
  74. });
  75. describe("using esversion 5", function() {
  76. it("should get pipeline aggs", function() {
  77. expect(queryDef.getMetricAggTypes(5).length).to.be(11);
  78. });
  79. });
  80. });
  81. });