-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
/* | ||
* 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 as unknown as string, // type workaround to send wrong data validation | ||
}; | ||
|
||
await expect(unmuteAll(context, invalidParams)).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Error validating unmute all parameters - [id]: expected value of type [string] but got [number]"` | ||
); | ||
}); | ||
}); |