constants.spec.tsx 2.8 KB

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