-
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
1 parent
6165e19
commit c2a14e7
Showing
451 changed files
with
10,865 additions
and
10,871 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
x-pack/legacy/plugins/watcher/__jest__/client_integration/helpers/constants.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; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getWatch } from '../../../test/fixtures'; | ||
|
||
export const WATCH_ID = 'my-test-watch'; | ||
|
||
export const WATCH = { watch: getWatch({ id: WATCH_ID }) }; |
158 changes: 158 additions & 0 deletions
158
x-pack/legacy/plugins/watcher/__jest__/client_integration/helpers/http_requests.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,158 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import sinon, { SinonFakeServer } from 'sinon'; | ||
import { ROUTES } from '../../../common/constants'; | ||
|
||
const { API_ROOT } = ROUTES; | ||
|
||
type HttpResponse = Record<string, any> | any[]; | ||
|
||
const mockResponse = (defaultResponse: HttpResponse, response: HttpResponse) => [ | ||
200, | ||
{ 'Content-Type': 'application/json' }, | ||
JSON.stringify({ ...defaultResponse, ...response }), | ||
]; | ||
|
||
// Register helpers to mock HTTP Requests | ||
const registerHttpRequestMockHelpers = (server: SinonFakeServer) => { | ||
const setLoadWatchesResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watches: [] }; | ||
|
||
server.respondWith('GET', `${API_ROOT}/watches`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setLoadWatchResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watch: {} }; | ||
server.respondWith('GET', `${API_ROOT}/watch/:id`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setLoadWatchHistoryResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watchHistoryItems: [] }; | ||
server.respondWith( | ||
'GET', | ||
`${API_ROOT}/watch/:id/history?startTime=*`, | ||
mockResponse(defaultResponse, response) | ||
); | ||
}; | ||
|
||
const setLoadWatchHistoryItemResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watchHistoryItem: {} }; | ||
server.respondWith('GET', `${API_ROOT}/history/:id`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setDeleteWatchResponse = (response?: HttpResponse, error?: any) => { | ||
const status = error ? error.status || 400 : 200; | ||
const body = error ? JSON.stringify(error.body) : JSON.stringify(response); | ||
|
||
server.respondWith('POST', `${API_ROOT}/watches/delete`, [ | ||
status, | ||
{ 'Content-Type': 'application/json' }, | ||
body, | ||
]); | ||
}; | ||
|
||
const setSaveWatchResponse = (id: string, response?: HttpResponse, error?: any) => { | ||
const status = error ? error.status || 400 : 200; | ||
const body = error ? JSON.stringify(error.body) : JSON.stringify(response); | ||
|
||
server.respondWith('PUT', `${API_ROOT}/watch/${id}`, [ | ||
status, | ||
{ 'Content-Type': 'application/json' }, | ||
body, | ||
]); | ||
}; | ||
|
||
const setLoadExecutionResultResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watchHistoryItem: {} }; | ||
server.respondWith('PUT', `${API_ROOT}/watch/execute`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setLoadMatchingIndicesResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { indices: [] }; | ||
server.respondWith('POST', `${API_ROOT}/indices`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setLoadEsFieldsResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { fields: [] }; | ||
server.respondWith('POST', `${API_ROOT}/fields`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setLoadSettingsResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { action_types: {} }; | ||
server.respondWith('GET', `${API_ROOT}/settings`, mockResponse(defaultResponse, response)); | ||
}; | ||
|
||
const setLoadWatchVisualizeResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { visualizeData: {} }; | ||
server.respondWith( | ||
'POST', | ||
`${API_ROOT}/watch/visualize`, | ||
mockResponse(defaultResponse, response) | ||
); | ||
}; | ||
|
||
const setDeactivateWatchResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watchStatus: {} }; | ||
server.respondWith( | ||
'PUT', | ||
`${API_ROOT}/watch/:id/deactivate`, | ||
mockResponse(defaultResponse, response) | ||
); | ||
}; | ||
|
||
const setActivateWatchResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watchStatus: {} }; | ||
server.respondWith( | ||
'PUT', | ||
`${API_ROOT}/watch/:id/activate`, | ||
mockResponse(defaultResponse, response) | ||
); | ||
}; | ||
|
||
const setAcknowledgeWatchResponse = (response: HttpResponse = {}) => { | ||
const defaultResponse = { watchStatus: {} }; | ||
server.respondWith( | ||
'PUT', | ||
`${API_ROOT}/watch/:id/action/:actionId/acknowledge`, | ||
mockResponse(defaultResponse, response) | ||
); | ||
}; | ||
|
||
return { | ||
setLoadWatchesResponse, | ||
setLoadWatchResponse, | ||
setLoadWatchHistoryResponse, | ||
setLoadWatchHistoryItemResponse, | ||
setDeleteWatchResponse, | ||
setSaveWatchResponse, | ||
setLoadExecutionResultResponse, | ||
setLoadMatchingIndicesResponse, | ||
setLoadEsFieldsResponse, | ||
setLoadSettingsResponse, | ||
setLoadWatchVisualizeResponse, | ||
setDeactivateWatchResponse, | ||
setActivateWatchResponse, | ||
setAcknowledgeWatchResponse, | ||
}; | ||
}; | ||
|
||
export const init = () => { | ||
const server = sinon.fakeServer.create(); | ||
server.respondImmediately = true; | ||
|
||
// Define default response for unhandled requests. | ||
// We make requests to APIs which don't impact the component under test, e.g. UI metric telemetry, | ||
// and we can mock them all with a 200 instead of mocking each one individually. | ||
server.respondWith([200, {}, 'DefaultResponse']); | ||
|
||
const httpRequestsMockHelpers = registerHttpRequestMockHelpers(server); | ||
|
||
return { | ||
server, | ||
httpRequestsMockHelpers, | ||
}; | ||
}; |
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/watcher/__jest__/client_integration/helpers/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,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { setup as watchListSetup } from './watch_list.helpers'; | ||
import { setup as watchStatusSetup } from './watch_status.helpers'; | ||
import { setup as watchCreateJsonSetup } from './watch_create_json.helpers'; | ||
import { setup as watchCreateThresholdSetup } from './watch_create_threshold.helpers'; | ||
import { setup as watchEditSetup } from './watch_edit.helpers'; | ||
|
||
export { nextTick, getRandomString, findTestSubject, TestBed } from '../../../../../../test_utils'; | ||
|
||
export { setupEnvironment } from './setup_environment'; | ||
|
||
export const pageHelpers = { | ||
watchList: { setup: watchListSetup }, | ||
watchStatus: { setup: watchStatusSetup }, | ||
watchCreateJson: { setup: watchCreateJsonSetup }, | ||
watchCreateThreshold: { setup: watchCreateThresholdSetup }, | ||
watchEdit: { setup: watchEditSetup }, | ||
}; |
32 changes: 32 additions & 0 deletions
32
x-pack/legacy/plugins/watcher/__jest__/client_integration/helpers/setup_environment.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,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import axios from 'axios'; | ||
import axiosXhrAdapter from 'axios/lib/adapters/xhr'; | ||
import { init as initHttpRequests } from './http_requests'; | ||
import { setHttpClient, setSavedObjectsClient } from '../../../public/lib/api'; | ||
|
||
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter }); | ||
|
||
const mockSavedObjectsClient = () => { | ||
return { | ||
find: (_params?: any) => {}, | ||
}; | ||
}; | ||
|
||
export const setupEnvironment = () => { | ||
const { server, httpRequestsMockHelpers } = initHttpRequests(); | ||
|
||
// @ts-ignore | ||
setHttpClient(mockHttpClient); | ||
|
||
setSavedObjectsClient(mockSavedObjectsClient()); | ||
|
||
return { | ||
server, | ||
httpRequestsMockHelpers, | ||
}; | ||
}; |
Oops, something went wrong.