Browse Source

ref: Refactor Incident fixture to be typescript (#55947)

Ryan Albrecht 1 year ago
parent
commit
cfb42b0b61

+ 10 - 2
fixtures/js-stubs/incident.js → fixtures/js-stubs/incident.ts

@@ -1,6 +1,9 @@
+import type {Incident as TIncident} from 'sentry/views/alerts/types';
+import {IncidentStatus, IncidentStatusMethod} from 'sentry/views/alerts/types';
+
 import {MetricRule} from './metricRule';
 
-export function Incident(params = {}) {
+export function Incident(params: Partial<TIncident> = {}): TIncident {
   return {
     id: '321',
     identifier: '123',
@@ -10,7 +13,7 @@ export function Incident(params = {}) {
     dateDetected: '2016-04-05T19:44:05.963Z',
     dateCreated: '2016-04-05T19:44:05.963Z',
     title: 'Too many Chrome errors',
-    status: 0,
+    status: IncidentStatus.CLOSED,
     projects: [],
     isSubscribed: true,
     alertRule: MetricRule(params.alertRule),
@@ -56,6 +59,11 @@ export function Incident(params = {}) {
         dateCreated: '2022-03-26T12:00:00Z',
       },
     ],
+    discoverQuery: '',
+    groups: [],
+    hasSeen: false,
+    seenBy: [],
+    statusMethod: IncidentStatusMethod.MANUAL,
     ...params,
   };
 }

+ 2 - 6
fixtures/js-stubs/metricRule.ts

@@ -1,13 +1,10 @@
+import type {MetricRule as TMetricRule} from 'sentry/views/alerts/rules/metric/types';
 import {Dataset} from 'sentry/views/alerts/rules/metric/types';
-import {CombinedAlertType, CombinedMetricIssueAlerts} from 'sentry/views/alerts/types';
 
 import {IncidentTrigger} from './incidentTrigger';
 
-export function MetricRule<
-  T extends CombinedMetricIssueAlerts & {type: CombinedAlertType.METRIC}
->(params: Partial<T> = {}): CombinedMetricIssueAlerts {
+export function MetricRule(params: Partial<TMetricRule> = {}): TMetricRule {
   return {
-    type: CombinedAlertType.METRIC,
     status: 0,
     dateCreated: '2019-07-31T23:02:02.731Z',
     dataset: Dataset.ERRORS,
@@ -15,7 +12,6 @@ export function MetricRule<
     id: '4',
     name: 'My Incident Rule',
     timeWindow: 60,
-    aggregation: 0,
     aggregate: 'count()',
     projects: ['project-slug'],
     dateModified: '2019-07-31T23:02:02.731Z',

+ 0 - 2
static/app/views/alerts/rules/metric/edit.spec.tsx

@@ -114,7 +114,6 @@ describe('MetricRulesEdit', function () {
       expect.anything(),
       expect.objectContaining({
         data: expect.objectContaining({
-          aggregation: 0,
           dataset: 'events',
           id: '4',
           name: 'My Incident Rule',
@@ -200,7 +199,6 @@ describe('MetricRulesEdit', function () {
       expect.anything(),
       expect.objectContaining({
         data: expect.objectContaining({
-          aggregation: 0,
           dataset: 'events',
           id: '4',
           name: 'My Incident Rule',