forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Response Ops][Rules] Version Unmute All Rule API (elastic#196070)
## Summary `POST /api/alerting/rule/{id}/_unmute_all` in elastic#195181 (cherry picked from commit c901fec)
- Loading branch information
Showing
17 changed files
with
224 additions
and
33 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/alerting/common/routes/rule/apis/unmute_all/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { unmuteAllRuleRequestParamsSchema } from './schemas/latest'; | ||
export type { UnmuteAllRuleRequestParams } from './types/latest'; | ||
|
||
export { unmuteAllRuleRequestParamsSchema as unmuteAllRuleRequestParamsSchemaV1 } from './schemas/v1'; | ||
export type { UnmuteAllRuleRequestParams as UnmuteAllRuleRequestParamsV1 } from './types/v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/unmute_all/schemas/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/alerting/common/routes/rule/apis/unmute_all/schemas/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
export const unmuteAllRuleRequestParamsSchema = schema.object({ | ||
id: schema.string({ | ||
meta: { | ||
description: 'The identifier for the rule.', | ||
}, | ||
}), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/unmute_all/types/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; |
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/alerting/common/routes/rule/apis/unmute_all/types/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TypeOf } from '@kbn/config-schema'; | ||
import { unmuteAllRuleRequestParamsSchemaV1 } from '..'; | ||
|
||
export type UnmuteAllRuleRequestParams = TypeOf<typeof unmuteAllRuleRequestParamsSchemaV1>; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/unmute_all/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { unmuteAll } from './unmute_all'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/unmute_all/schemas/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './unmute_all_rule_schemas'; |
12 changes: 12 additions & 0 deletions
12
...ns/alerting/server/application/rule/methods/unmute_all/schemas/unmute_all_rule_schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
export const unmuteAllRuleParamsSchema = schema.object({ | ||
id: schema.string(), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/unmute_all/types/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './unmute_all_rule_types'; |
11 changes: 11 additions & 0 deletions
11
...lugins/alerting/server/application/rule/methods/unmute_all/types/unmute_all_rule_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TypeOf } from '@kbn/config-schema'; | ||
import { unmuteAllRuleParamsSchema } from '../schemas'; | ||
|
||
export type UnmuteAllRuleParams = TypeOf<typeof unmuteAllRuleParamsSchema>; |
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/alerting/server/application/rule/methods/unmute_all/unmute_all.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { RulesClientContext } from '../../../../rules_client'; | ||
import { unmuteAll } from './unmute_all'; | ||
import { savedObjectsRepositoryMock } from '@kbn/core-saved-objects-api-server-mocks'; | ||
|
||
jest.mock('../../../../lib/retry_if_conflicts', () => ({ | ||
retryIfConflicts: (_: unknown, id: unknown, asyncFn: () => Promise<unknown>) => { | ||
return asyncFn(); | ||
}, | ||
})); | ||
|
||
jest.mock('../../../../rules_client/lib', () => ({ | ||
updateMetaAttributes: () => {}, | ||
})); | ||
|
||
jest.mock('../../../../saved_objects', () => ({ | ||
partiallyUpdateRule: async () => {}, | ||
})); | ||
|
||
const loggerErrorMock = jest.fn(); | ||
const getBulkMock = jest.fn(); | ||
|
||
const savedObjectsMock = savedObjectsRepositoryMock.create(); | ||
savedObjectsMock.get = jest.fn().mockReturnValue({ | ||
attributes: { | ||
actions: [], | ||
}, | ||
version: '9.0.0', | ||
}); | ||
|
||
const context = { | ||
logger: { error: loggerErrorMock }, | ||
getActionsClient: () => { | ||
return { | ||
getBulk: getBulkMock, | ||
}; | ||
}, | ||
unsecuredSavedObjectsClient: savedObjectsMock, | ||
authorization: { ensureAuthorized: async () => {} }, | ||
ruleTypeRegistry: { | ||
ensureRuleTypeEnabled: () => {}, | ||
}, | ||
getUserName: async () => {}, | ||
} as unknown as RulesClientContext; | ||
|
||
describe('validate unmuteAll parameters', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should not throw an error for valid params', () => { | ||
const validParams = { | ||
id: 'ble', | ||
}; | ||
|
||
expect(() => unmuteAll(context, validParams)).not.toThrow(); | ||
expect(savedObjectsMock.get).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw Boom.badRequest for invalid params', async () => { | ||
const invalidParams = { | ||
id: 22, | ||
}; | ||
|
||
// @ts-expect-error wrong type for testing purposes | ||
await expect(unmuteAll(context, invalidParams)).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Error validating unmute all parameters - [id]: expected value of type [string] but got [number]"` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/routes/rule/apis/unmute_all/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { unmuteAllRuleRoute } from './unmute_all_rule'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters