constants.spec.tsx 2.8 KB

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