constants.spec.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {UserFixture} from 'sentry-fixture/user';
  2. import type {EventViewOptions} from 'sentry/utils/discover/eventView';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {createRuleFromEventView} from 'sentry/views/alerts/rules/metric/constants';
  5. import {Dataset, EventTypes} from 'sentry/views/alerts/rules/metric/types';
  6. describe('createRuleFromEventView()', () => {
  7. const commonEventViewProps: EventViewOptions = {
  8. createdBy: UserFixture(),
  9. id: '',
  10. name: '',
  11. start: '',
  12. end: '',
  13. environment: [],
  14. project: [],
  15. fields: [],
  16. query: '',
  17. topEvents: undefined,
  18. display: undefined,
  19. sorts: [],
  20. team: [],
  21. statsPeriod: '14d',
  22. };
  23. it('sets transaction dataset from event.type:transaction', () => {
  24. const eventView = new EventView({
  25. ...commonEventViewProps,
  26. query: 'title:"nothing" event.type:transaction',
  27. });
  28. const rule = createRuleFromEventView(eventView);
  29. expect(rule.dataset).toBe(Dataset.TRANSACTIONS);
  30. });
  31. it('sets error dataset from event.type:error', () => {
  32. const eventView = new EventView({
  33. ...commonEventViewProps,
  34. query: 'title:"nothing" event.type:error',
  35. });
  36. const rule = createRuleFromEventView(eventView);
  37. expect(rule.dataset).toBe(Dataset.ERRORS);
  38. expect(rule.eventTypes).toEqual([EventTypes.ERROR]);
  39. });
  40. it('removes event.type from query', () => {
  41. const eventView = new EventView({
  42. ...commonEventViewProps,
  43. query: 'title:"nothing" event.type:error',
  44. });
  45. const rule = createRuleFromEventView(eventView);
  46. expect(rule.query).toBe('title:"nothing"');
  47. });
  48. it('gets environment from EventView', () => {
  49. const eventView = new EventView({
  50. ...commonEventViewProps,
  51. environment: ['beta'],
  52. });
  53. const rule = createRuleFromEventView(eventView);
  54. expect(rule.environment).toBe('beta');
  55. });
  56. it('gets aggregate from EventView.yAxis', () => {
  57. const eventView = new EventView({
  58. ...commonEventViewProps,
  59. yAxis: 'count_unique(user)',
  60. });
  61. const rule = createRuleFromEventView(eventView);
  62. expect(rule.aggregate).toBe(eventView.yAxis);
  63. });
  64. it('gets dataset and eventtypes from query', () => {
  65. const eventView = new EventView({
  66. ...commonEventViewProps,
  67. query: 'event.type:error or event.type:default something',
  68. });
  69. const rule = createRuleFromEventView(eventView);
  70. expect(rule.dataset).toBe(Dataset.ERRORS);
  71. expect(rule.eventTypes).toEqual([EventTypes.ERROR, EventTypes.DEFAULT]);
  72. });
  73. it('allows pXX transaction querys', () => {
  74. const eventView = EventView.fromSavedQuery({
  75. id: undefined,
  76. name: '',
  77. dateCreated: '',
  78. dateUpdated: '',
  79. version: 1,
  80. query: 'event.type:transaction',
  81. yAxis: ['p95()'],
  82. fields: ['p95()'],
  83. });
  84. const rule = createRuleFromEventView(eventView);
  85. expect(rule.aggregate).toBe('p95(transaction.duration)');
  86. });
  87. });