getMetricRuleDiscoverUrl.spec.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {MetricRuleFixture} from 'sentry-fixture/metricRule';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  4. import {getMetricRuleDiscoverQuery} from './getMetricRuleDiscoverUrl';
  5. describe('getMetricRuleDiscoverQuery', () => {
  6. it('should use metric aggregate in discover query', () => {
  7. const rule = MetricRuleFixture({
  8. aggregate: 'failure_rate()',
  9. dataset: Dataset.TRANSACTIONS,
  10. });
  11. const projects = [ProjectFixture()];
  12. const query = getMetricRuleDiscoverQuery({
  13. rule,
  14. projects,
  15. timePeriod: {
  16. period: '7d',
  17. usingPeriod: true,
  18. start: new Date().toISOString(),
  19. end: new Date().toISOString(),
  20. },
  21. });
  22. expect(query!.valueOf()).toEqual(
  23. expect.objectContaining({
  24. statsPeriod: '7d',
  25. fields: [
  26. {
  27. field: 'transaction',
  28. width: -1,
  29. },
  30. {
  31. field: 'project',
  32. width: -1,
  33. },
  34. {
  35. field: 'failure_rate()',
  36. width: -1,
  37. },
  38. {
  39. field: 'count_unique(user)',
  40. width: -1,
  41. },
  42. {
  43. field: 'user_misery(300)',
  44. width: -1,
  45. },
  46. ],
  47. })
  48. );
  49. });
  50. });