Skip to content

Commit

Permalink
reduce repetition of mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Nov 30, 2020
1 parent 2699660 commit 23f1433
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 148 deletions.
10 changes: 5 additions & 5 deletions x-pack/plugins/alerts/public/alert_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertType } from '../common';
import { AlertType, RecoveredActionGroup } from '../common';
import { httpServiceMock } from '../../../../src/core/public/mocks';
import { loadAlert, loadAlertState, loadAlertType, loadAlertTypes } from './alert_api';
import uuid from 'uuid';
Expand All @@ -22,7 +22,7 @@ describe('loadAlertTypes', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: { id: 'recovered', name: 'Recovered' },
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
];
Expand All @@ -46,7 +46,7 @@ describe('loadAlertType', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: { id: 'recovered', name: 'Recovered' },
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
};
http.get.mockResolvedValueOnce([alertType]);
Expand All @@ -67,7 +67,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: { id: 'recovered', name: 'Recovered' },
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
};
http.get.mockResolvedValueOnce([alertType]);
Expand All @@ -83,7 +83,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: { id: 'recovered', name: 'Recovered' },
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { AlertNavigationRegistry } from './alert_navigation_registry';
import { AlertType, SanitizedAlert } from '../../common';
import { AlertType, RecoveredActionGroup, SanitizedAlert } from '../../common';
import uuid from 'uuid';

beforeEach(() => jest.resetAllMocks());
Expand All @@ -14,10 +14,7 @@ const mockAlertType = (id: string): AlertType => ({
id,
name: id,
actionGroups: [],
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
actionVariables: [],
defaultActionGroupId: 'default',
producer: 'alerts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AlertsAuthorization } from '../../authorization/alerts_authorization';
import { ActionsAuthorization } from '../../../../actions/server';
import { getBeforeSetup, setGlobalDate } from './lib';
import { AlertExecutionStatusValues } from '../../types';
import { RecoveredActionGroup } from '../../../common';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -53,10 +54,7 @@ describe('aggregate()', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myType',
name: 'myType',
producer: 'myApp',
Expand Down Expand Up @@ -106,10 +104,7 @@ describe('aggregate()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
authorizedConsumers: {
myApp: { read: true, all: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AlertsAuthorization } from '../../authorization/alerts_authorization';
import { ActionsAuthorization, ActionsClient } from '../../../../actions/server';
import { TaskStatus } from '../../../../task_manager/server';
import { getBeforeSetup, setGlobalDate } from './lib';
import { RecoveredActionGroup } from '../../../common';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -683,10 +684,7 @@ describe('create()', () => {
},
],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
validate: {
params: schema.object({
param1: schema.string(),
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/alerts/server/alerts_client/tests/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
import { AlertsAuthorization } from '../../authorization/alerts_authorization';
import { ActionsAuthorization } from '../../../../actions/server';
import { getBeforeSetup, setGlobalDate } from './lib';
import { RecoveredActionGroup } from '../../../common';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -52,7 +53,7 @@ describe('find()', () => {
const listedTypes = new Set([
{
actionGroups: [],
recoveryActionGroup: { id: 'recovered', name: 'recovered' },
recoveryActionGroup: RecoveredActionGroup,
actionVariables: undefined,
defaultActionGroupId: 'default',
id: 'myType',
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('find()', () => {
id: 'myType',
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
recoveryActionGroup: { id: 'recovered', name: 'recovered' },
recoveryActionGroup: RecoveredActionGroup,
defaultActionGroupId: 'default',
producer: 'alerts',
authorizedConsumers: {
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/alerts/server/alerts_client/tests/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { actionsClientMock } from '../../../../actions/server/mocks';
import { ConstructorOptions } from '../alerts_client';
import { eventLogClientMock } from '../../../../event_log/server/mocks';
import { AlertTypeRegistry } from '../../alert_type_registry';
import { RecoveredActionGroup } from '../../../common';

export const mockedDateString = '2019-02-12T21:01:22.479Z';

Expand Down Expand Up @@ -82,10 +83,7 @@ export function getBeforeSetup(
id: '123',
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
defaultActionGroupId: 'default',
async executor() {},
producer: 'alerts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
import { AlertsAuthorization } from '../../authorization/alerts_authorization';
import { ActionsAuthorization } from '../../../../actions/server';
import { getBeforeSetup } from './lib';
import { RecoveredActionGroup } from '../../../common';

const taskManager = taskManagerMock.createStart();
const alertTypeRegistry = alertTypeRegistryMock.create();
Expand Down Expand Up @@ -50,10 +51,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'alertingAlertType',
name: 'alertingAlertType',
producer: 'alerts',
Expand All @@ -62,10 +60,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myAppAlertType',
name: 'myAppAlertType',
producer: 'myApp',
Expand Down Expand Up @@ -104,10 +99,7 @@ describe('listAlertTypes', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myType',
name: 'myType',
producer: 'myApp',
Expand All @@ -117,10 +109,7 @@ describe('listAlertTypes', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
]);
Expand All @@ -135,10 +124,7 @@ describe('listAlertTypes', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
authorizedConsumers: {
myApp: { read: true, all: true },
Expand Down
16 changes: 4 additions & 12 deletions x-pack/plugins/alerts/server/alerts_client/tests/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { taskManagerMock } from '../../../../task_manager/server/mocks';
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
import { alertsAuthorizationMock } from '../../authorization/alerts_authorization.mock';
import { IntervalSchedule, InvalidatePendingApiKey } from '../../types';
import { RecoveredActionGroup } from '../../../common';
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
import { AlertsAuthorization } from '../../authorization/alerts_authorization';
Expand Down Expand Up @@ -97,10 +98,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
});
Expand Down Expand Up @@ -680,10 +678,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
validate: {
params: schema.object({
param1: schema.string(),
Expand Down Expand Up @@ -1029,10 +1024,7 @@ describe('update()', () => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ActionsAuthorization } from '../../actions/server';
import { SavedObjectsErrorHelpers } from '../../../../src/core/server';
import { RetryForConflictsAttempts } from './lib/retry_if_conflicts';
import { TaskStatus } from '../../../plugins/task_manager/server/task';
import { RecoveredActionGroup } from '../common';

let alertsClient: AlertsClient;

Expand Down Expand Up @@ -331,10 +332,7 @@ beforeEach(() => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
}));
Expand All @@ -344,10 +342,7 @@ beforeEach(() => {
name: 'Test',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'alerts',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AlertsAuthorization, WriteOperations, ReadOperations } from './alerts_a
import { alertsAuthorizationAuditLoggerMock } from './audit_logger.mock';
import { AlertsAuthorizationAuditLogger, AuthorizationResult } from './audit_logger';
import uuid from 'uuid';
import { RecoveredActionGroup } from '../../common';

const alertTypeRegistry = alertTypeRegistryMock.create();
const features: jest.Mocked<FeaturesStartContract> = featuresPluginMock.createStart();
Expand Down Expand Up @@ -172,10 +173,7 @@ beforeEach(() => {
name: 'My Alert Type',
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
async executor() {},
producer: 'myApp',
}));
Expand Down Expand Up @@ -538,10 +536,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myOtherAppAlertType',
name: 'myOtherAppAlertType',
producer: 'alerts',
Expand All @@ -550,10 +545,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myAppAlertType',
name: 'myAppAlertType',
producer: 'myApp',
Expand All @@ -562,10 +554,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'mySecondAppAlertType',
name: 'mySecondAppAlertType',
producer: 'myApp',
Expand Down Expand Up @@ -840,10 +829,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myOtherAppAlertType',
name: 'myOtherAppAlertType',
producer: 'myOtherApp',
Expand All @@ -852,10 +838,7 @@ describe('AlertsAuthorization', () => {
actionGroups: [],
actionVariables: undefined,
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'recovered',
name: 'Recovered',
},
recoveryActionGroup: RecoveredActionGroup,
id: 'myAppAlertType',
name: 'myAppAlertType',
producer: 'myApp',
Expand Down
Loading

0 comments on commit 23f1433

Please sign in to comment.